PDO连接时,提示"unknown mysql server host"
2016-12-21 15:30
645 查看
在 CentOS7 上运行项目,但是不断的提示报错“SQLSTATE[HY000] [2005] Unknown MySQL server host ‘127.0.0.1:3306’ (110)”,找到报错位置后,发现代码如下:
参考 PDO connect to localhost (unknown mysql server host) ,把第一行代码的端口修改下,就可以运行了,奇怪的是在windows下面,这样写却没有问题。
$dsn = "mysql:host=127.0.0.1:3306;dbname=test"; try { $pdo = new PDO($dsn, root, root); //初始化一个PDO对象,就是创建了数据库连接对象 $pdo->exec("SET NAMES 'utf8';"); self::$link[$rand] = $pdo; } catch (PDOException $e) { if($auto_connect) { //省略 } die ($e->getMessage() . "<br/>"); }
参考 PDO connect to localhost (unknown mysql server host) ,把第一行代码的端口修改下,就可以运行了,奇怪的是在windows下面,这样写却没有问题。
$dsn = "mysql:host=127.0.0.1;port=3306;dbname=test";
相关文章推荐
- php PDO连接时,提示"unknown mysql server host"
- mysql连接提示"Host 'XXX' is not allowed to connect to this MySql server"
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- OperationalError: (2005, "Unknown MySQL server host 'localhost' (11001)")
- 远程连接MySQL提示 Host is not allowed to connect to this MySQL server
- jdbc连接mysql时报message from server: "Host '**' is not allowed to connect to this MySQL server"错误解决
- 远程连接MYSQL提示 Host *** is not allowed to connect to this MySQL server
- 连接MySQL数据库报 "Host XXX.XXX.XXX.XXX is not allowed to connect to this MySQL server " 解决办法。
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 主机连接虚拟机MySQL报错:Can't connect to Mysql server on '192.168.33.10' (10061 "Unknown error")
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- Unexpected exception of type [PDOException][HY000] [2005] Unknown MySQL server host
- 远程连接MySQL数据库提示错误Host is not allowed to connect this MySQL server
- 远程连接MYSQL提示:Host XXX is not allowed to connect to this MySQL server 解决办法
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server
- 远程连接MYSQL提示Host is not allowed to connect to this MySQL server