I'm trying to access a database from a client (ip 172.16.0.114). Both the server and client are running the Fedora distribution of Linux. 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'.
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:
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:
service mysqld start
or on Fedora release >= 16, which relies on 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:
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). If the port is not the default port, you must set the connection port on the client. If using mysql client:
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:
bind_address=127.0.0.1
if the address is 127.0.0.1 only local connections are allowed; if it were 172.16.1.0, you could not connect from 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); if it's a redhat/fedora/centos run
service iptables status
Open MySQL config file
sudo vim my.cnf
Ensure that the following are commented out.
#skip-external-locking
#skip-networking
#bind-address = xx.xx.xx.xx
Save and exit
Restart mysql service
In MySQL config file (/etc/mysql/my.cnf) comment '#bind-address = 127.0.0.1'
Save and restart mysql service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With