Problems in connecting to mysql server: ERROR 2003 (HY000) - mysql

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

Specifying hostname for MySQL server - connection refused

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

How to log in mysql DB in remote host [duplicate]

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)

Slave I/O: error connecting to master

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

Linux Centos 6.6: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I am trying to connect with mysql 5.6 in Linux with:
[C003#C-003 mysql]$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
I am getting above error. I found lot of hints but not one working for me and I cant take so much risks for Live server.
some commands output as follow:
[C003#C-003 mysql]$ service mysql status
ERROR! MySQL is running but PID file could not be found
[C003#C-003 mysql]$ ps -ef|grep mysql
root 1419 1 0 Apr28 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/SI-CloudDB-003.pid
mysql 1731 1419 6 Apr28 ? 20:58:36 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/SI-CloudDB-003.err --pid-file=/var/lib/mysql/SI-CloudDB-003.pid --socket=/var/lib/mysql/mysql.sock --port=3310
501 30843 28738 0 11:41 pts/2 00:00:00 grep mysql
This issue occurred if you have changed default datadir location..
You need to create softlink in this case.. follow the below steps:
Step1: Stop DB service
service mysqld stop
Step2: create softlink on default location i.e. /var/lib pointing to new DB data location.
ln -s /Data/lib/mysql mysql
Step3: restart mysqld service
service mysqld restart
You should able to connect the mysql db...
Check that /var/lib/mysql/mysql.sock exists and what ownership/permissions does the file have
Issue fixed. I create file at /var/lib/mysql/mysql.sock and set ownership to MySQL user and group. When try to shutdown the service I got error "Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'". I kill the mysql background process through kill -9 process_id and then start the mysql service. Now its working fine.

Connecting to MySQL from Workbench

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