php 尝试连接到远程 MySQL 服务器时出现“与 MySQL 服务器的连接丢失”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4499968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Lost connection to MySQL server" when trying to connect to remote MySQL server
提问by Karthikeyan
I am using Zend Framework to develop my application and I try to connect to a remote MySQL database in my LAN.
我正在使用 Zend Framework 开发我的应用程序,并尝试连接到我局域网中的远程 MySQL 数据库。
The database connection settings in Zend is as follows:
Zend中的数据库连接设置如下:
[GENERAL] db.adapter = PDO_MYSQL db.params.host = 192.168.1.2 db.params.port = 3306[LIVE:GENERAL] db.params.username = root db.params.password = ** db.params.dbname = djudd
[DEVELOPMENT:GENERAL] db.params.username = root db.params.password = ** db.params.dbname = stellarengine
I got the following error:
我收到以下错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111' in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace: #0 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=192....', 'root', 'password', Array) #1 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() #2 /usr/share/php/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect() #3 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE
bny_c...', Array) #4 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBEbny_c...') #5 /usr/share/php/Zend/Db/Table/Abstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('bny_core_module...', NULL) #6 /usr/share/php/Zend/Db/Table/Abstract.php(866): Zend_Db_Table_Abstract->_setupMetadata() #7 /usr/share/php/Zend/Db/Table/Abstract. in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php on line 144
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111' in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace: #0 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:host=192....', 'root', 'password', Array) #1 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect() #2 /usr/share/php/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect() #3 /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE
bny_c...', Array) #4 /usr/share/php/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBEbny_c...') #5 /usr/share/php/Zend/Db/Table/Abstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('bny_core_module...', NULL) #6 /usr/share/php/Zend/Db/Table/Abstract.php(866): Zend_Db_Table_Abstract->_setupMetadata() #7 /usr/share/php/Zend/Db/Table/Abstract. in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php on line 144
Please help me to resolve this problem.
请帮我解决这个问题。
回答by pdolinaj
Last time I had this type of error, I had to change my host from: 127.0.0.1to 'localhost' and then it worked fine.
上次我遇到这种类型的错误时,我不得不将我的主机从:127.0.0.1更改为“ localhost”,然后它工作正常。
回答by Srisa
This might help: MySQL Forum: 'reading initial communication packet', system error: 111
这可能会有所帮助:MySQL 论坛:“正在读取初始通信数据包”,系统错误:111
回答by Flávio Botelho
I had the same problem, to solve it I changed the remote port in the tunnel configuration from 'localhost:3306' to '127.0.0.1:3306'.
我遇到了同样的问题,为了解决它,我将隧道配置中的远程端口从 'localhost:3306' to '127.0.0.1:3306'.
In the target machine, localhost was resolving to ::1 but MariaDB was not listening IPv6 requests...
在目标机器上,localhost 解析为 ::1 但 MariaDB 没有监听 IPv6 请求......
回答by Abhi Beckert
This error means you're connecting to the wrong server or the firewall blocked it or the server isn't running.
此错误意味着您连接到错误的服务器或防火墙阻止它或服务器未运行。
You'll need to contact the server administrator to confirm the correct details.
您需要联系服务器管理员以确认正确的详细信息。
With most servers you'll use 127.0.0.1
but some use localhost
while others (like media temple) will need a full domain name - for example internal-db.s421234.gridserver.com
对于大多数服务器,您将使用127.0.0.1
但有些使用,localhost
而其他服务器(如媒体寺)将需要完整的域名 - 例如internal-db.s421234.gridserver.com