[英]Problems in connecting to mysql server: ERROR 2003 (HY000)
I'm trying to access a database from a client (ip 172.16.0.114). 我正在尝试从客户端(ip 172.16.0.114)访问数据库。 Both the server and client are running the Fedora distribution of Linux.
服务器和客户端都运行Linux的Fedora发行版。 What settings need to be configured, and what should they be set to, for both the server and client?
服务器和客户端都需要配置什么设置,以及应该将它们设置为什么? How do I access a specific database (here, "example")?
如何访问特定的数据库(此处为“示例”)? I tried but I got an error:
我尝试过,但出现错误:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.1.169'.
错误2003(HY000):无法连接到“ 172.16.1.169”上的MySQL服务器。
That error message is generated by the client (not the server) because a connection to the server has been attempted but the server could not be reached. 该错误消息是由客户端(而不是服务器)生成的,因为已尝试与服务器建立连接,但无法访问服务器。
There are various possible causes to that: 有多种可能的原因:
1) check that mysqld is running on the server: 1)检查mysqld是否在服务器上运行:
ps -ef | grep mysqld
should return something like: 应该返回类似:
root 2435 2342 0 15:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/var/ --user=mysql
mysql 2480 2435 0 15:49 pts/1 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/var/ --user=mysql ...
To run the daemon service, run on redhat/fedora/centos: 要运行守护程序服务,请在redhat / fedora / centos上运行:
service mysqld start
or on Fedora release >= 16, which relies on systemd: 或Fedora版本> = 16,它依赖于systemd:
systemctl start mysqld.service
and for enabling daemon auto-startup at system boot: 并在系统引导时启用守护程序自动启动:
systemctl enable mysqld.service
2) check the port on which mysqld is running on the server: 2)检查服务器上运行mysqld的端口:
netstat -lnp | grep mysql
should return: 应该返回:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2480/mysqld
unix 2 [ ACC ] STREAM LISTENING 8101 2480/mysqld /tmp/mysql.sock
the latter is the socket for local connections, the first the tcp port for networking (default 3306). 后者是用于本地连接的套接字,第一个是用于网络连接的tcp端口(默认为3306)。 If the port is not the default port, you must set the connection port on the client.
如果该端口不是默认端口,则必须在客户端上设置连接端口。 If using mysql client:
如果使用mysql客户端:
mysql dbname -uuser -ppasswd -P<port> ...
3) being on a different net address, check that the server listens for the net addrees your are connecting from: in file /etc/my.cnf
search for the line: 3)在不同的网络地址上,检查服务器是否侦听您正在连接的网络地址:在文件
/etc/my.cnf
搜索以下行:
bind_address=127.0.0.1
if the address is 127.0.0.1 only local connections are allowed; 如果地址是127.0.0.1,则仅允许本地连接; if it were 172.16.1.0, you could not connect from 172.16.2.xxx
如果是172.16.1.0,则无法从172.16.2.xxx连接
4) check that on the server there is no firewall running and blocking connections to mysql port (3306 is the default port); 4)检查服务器上是否没有运行防火墙并阻止与mysql端口的连接(默认端口3306); if it's a redhat/fedora/centos run
如果是redhat / fedora / centos运行
service iptables status
Open MySQL config file 打开MySQL配置文件
sudo vim my.cnf 须藤vim my.cnf
Ensure that the following are commented out. 确保将以下内容注释掉。
#skip-external-locking #skip-external-locking
#skip-networking #skip-networking
#bind-address = xx.xx.xx.xx #bind-address = xx.xx.xx.xx
Save and exit 保存并退出
Restart mysql service 重启mysql服务
I think the destination mysql
server might use a different port. 我认为目标
mysql
服务器可能使用其他端口。 You have to find the correct port first. 您必须首先找到正确的端口。
Once you get the correct port you can connect to that mysql
server by using this command: 一旦获得正确的端口,就可以使用以下命令连接到该
mysql
服务器:
mysql -h 172.16.1.169 -P (port) -u root -p (password)
In MySQL config file (/etc/mysql/my.cnf) comment '#bind-address = 127.0.0.1' 在MySQL配置文件(/etc/mysql/my.cnf)中注释'#bind-address = 127.0.0.1'
Save and restart mysql service. 保存并重新启动mysql服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.