Server ip: 172.16.1.169
mysql user name: root
passwd: xxxxxxxxxx
database name: example
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.
I think the destination mysql server might use a different port.
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 -h 172.16.1.169 -P (port) -u root -p (password)
Related
I deployed a SQL server on my Mac and configured so that root#% has access to it. I also modified my /etc/hosts to have a mapping between my Mac IP (192.168.1.60) and my MySQL server (192.168.1.60 mysql-server). I also added a binding in my.cnf and then restarted the server:
bind-address = 192.168.1.60
port = 3306
However, when I do (from my Mac): mysql -u root -h mysql-server, I can't connect to the MySQL server (and also when I do a "netcat mysql-server 3306", I have this response: nc: connectx to mysql-server port 3306 (tcp) failed: Connection refused).
Any recommendation ?
Many thanks - C
Configuring Multiple MySQL Instances Using systemd, mysql-documents,But how to use mysql client connect?
vim /etc/my.cnf
[mysqld#replica01]
datadir=/var/lib/mysql-replica01
socket=/var/lib/mysql-replica01/mysql.sock
port=3307
log-error=/var/log/mysqld-replica01.log
[mysqld#replica02]
datadir=/var/lib/mysql-replica02
socket=/var/lib/mysql-replica02/mysql.sock
port=3308
log-error=/var/log/mysqld-replica02.log
systemctl start mysqld#replica01
if I do this
shell> mysql -uroot -P3307
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
The mysql client will try to use socket connect by default, despite having received the port parameter in command line. You will need to instruct it to use tcp connection.
Either
mysql -h 127.0.0.1 -P 3307
or
mysql --protocol tcp -P 3307
will do it.
Another way to do it is to avoid tcp configuration parameters, and pass -S (--socket) pointing to socket for your desired instance. In this specific case:
mysql -S /var/lib/mysql-replica01/mysql.sock
I'm following this tutorial for Master-slave-replication
for my database replication and this working fine for test servers in which both servers have not ssl installed. But when I trying to do the same with my production server where only master has ssl installed not slave server, I'm getting this error Slave I/O: error connecting to master 'server-ipaddress:3306' - retry-time: 60 retries: 86400, Error_code: 2003. Is this problem of ssl connection or something else.
Also when setting up mysql configuration on master server after taking dump file of database and unlocking tables my mysql server shut down with my website showing this error error establishing database connection after restarting mysql my website working fine again.
My master server is running on nginx server with wordpress installed and I have also checked that 3306 is listening on my master server.
Why my slave unable to connect to my master server, any solution?
You can use command below to check the ip address mysql server is listening
netstat -nlt | grep 3306
sample result:
tcp 0 0 xxx.xxx.xxx.xxx:3306 0.0.0.0:* LISTEN
If the result showing same result like me then add a replication master user to access the server database.
If netfilter firewall is enabled (sudo ufw enable) on mysql server machine, do the following to open port 3306 for remote access:
sudo ufw allow 3306
check status again :
sudo ufw status
You will see your tcp port for 3306 is open for connection from anywhere. Now you try to connect from slave server you will get the result.
i solved like this:
sudo iptables -I INPUT 1 -p tcp -s ipmaster --dport 3306 -j ACCEPT
sudo iptables -I INPUT 2 -p tcp --dport 3306 -j DROP
MySQL remote access
I have a mysql database, running on Ubuntu Server 12.04 that I need to access remotely. For some reason this is become much more of a chore than I think it should be.
I have been through countless threads trying to resolve this issue with no luck what so ever. I do not have another linux box to test my connection. I am only using the MySQL Workbench from a Window 7 machine.
Here is what I have done so far:
set the iptables to accept
set the my.cnf to have the bind address of the server
created a user for both localhost and %
grant all to those users
restarted mysql
verified the user has all priv
verified mysql is listening on 3306
give the correct setting to Workbench and I get
"Your connection attempt failed for user 'USER' from your host to server at x.x.x.x:3306:
Can't connect to MySQL server on 'x.x.x.x' (10061)"
EDIT: I did notice that it show 'localhost and NOT the ipaddress when I run this cmd, but i'm not sure how to change that, or if it is even the issue. Thoughts?
# lsof -i -P | grep :3306
mysqld 5775 mysql 10u IPv4 154265 0t0 TCP localhost:3306 (LISTEN)
vim /etc/mysql/my.cnf
Change the following line to reflect as below:
(bind-address = 127.0.0.1)
bind-address = 0.0.0.0
Close the file then and restart mysql
To verify that mysql port 3306 is listening on all interfaces:
netstat -lnt | grep 3306
You should see this:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Find mysql config file (/etc/mysql/)
comment out the following line by putting a hash character in front of it as shown -> #bind-address = 127.0.0.1
-> Restart the server: sudo service mysql restart
Server ip: 172.16.1.169
mysql user name: root
passwd: xxxxxxxxxx
database name: example
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.
I think the destination mysql server might use a different port.
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 -h 172.16.1.169 -P (port) -u root -p (password)