php 无法连接到 MySQL 服务器错误 113
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30127665/
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
Can't connect to MySQL server error 113
提问by Jev
Trying to make a simple connect to my servers MySQL database and I get
尝试简单连接到我的服务器 MySQL 数据库,我得到
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '<host>' (113)
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '<host>' (113)
netstat -tulpen has a :3306 record
netstat -tulpen 有 :3306 记录
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 999 801279 32067/mysqld
My bind-address in my.cnf is set to 0.0.0.0
and I still can't manage to connect to a database.
我在 my.cnf 中的绑定地址设置为0.0.0.0
,但我仍然无法连接到数据库。
My MySQL users
我的 MySQL 用户
+------------------+------------------------+
| User | Host |
+------------------+------------------------+
| root | 127.0.0.1 |
| root | localhost |
| root | <ip> |
+------------------+------------------------+
I can connect from the inside of my server.
我可以从我的服务器内部连接。
What i'm missing?
我缺少什么?
Thank you in advance
先感谢您
回答by marc_s
the 113 error shows "no route to host" error.you must configure your ip address on both machines.
of course,it must be routable.else, it wont work.
113 错误显示“没有到主机的路由”错误。您必须在两台机器上配置您的 IP 地址。
当然,它必须是routable.else,它不会工作。
回答by Bee Kay
In your specific case, there are two options. The most likely is that your firewall is blocking that port still, so external cannot access. The alternative, and weirder one, is an identity issue. MySQL does not allow, by default, the admin user to login both internally AND externally. You will need to define a Host and User pair for this identity to be allowed somewhere other than "localhost" to login from.
在您的具体情况下,有两种选择。最有可能的是您的防火墙仍在阻止该端口,因此外部无法访问。另一种更奇怪的是身份问题。默认情况下,MySQL 不允许管理员用户在内部和外部登录。您需要为此身份定义一个主机和用户对,以允许从“本地主机”以外的其他地方登录。
首先登录mysql服务器,然后登录mysql服务。 root# mysql -u root -p
Next, open the database named "mysql" and look at your user of interest. My example will be my "root" user.
接下来,打开名为“mysql”的数据库并查看您感兴趣的用户。我的例子将是我的“root”用户。
mysql> use mysql;
mysql> select * from user where User="root";
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | root | *A86DD7ED2F8269DFFDC595311DF5FF08872C12AB | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| kickseed | root | *A86DD7ED2F8269DFFDC595311DF5FF08872C12AB | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| 127.0.0.1 | root | *A86DD7ED2F8269DFFDC595311DF5FF08872C12AB | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| 10.%.%.% | root | *A86DD7ED2F8269DFFDC595311DF5FF08872C12AB | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
As you can see, I have four separate entries for root: One for local, one for the loopback, one for server kickseed, and one for the development network. You will need to go through the create and grant steps as if it were a new user, and set your permissions accordingly.
如您所见,我有四个单独的 root 条目:一个用于本地,一个用于环回,一个用于服务器 kickseed,一个用于开发网络。您需要像新用户一样完成创建和授予步骤,并相应地设置您的权限。