Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

People also ask

How do I fix MySQL error code 2003?

The error (2003) Can't connect to MySQL server on ' server ' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.

Can not connect to MySQL server 111?

111 means connection refused, which in turn means that your mysqld only listens to the localhost interface. To alter it you may want to look at the bind-address value in the mysqld section of your my. cnf file. It's also worth checking if the port number is valid.

Can't connect to MySQL no route to host?

1) Check the mysql service that it is running. 2) Check the firewall that the mysql port is open. 3) If the database is located on a remote hosting check that the connection to your database can be opened. 4) If there is a router between the database, check the port forwarding.


If you are using ubuntu, you have to use the following steps to avoid this error(if there is no replication enabled):

  1. run the command vim /etc/mysql/my.cnf
  2. comment bind-address = 127.0.0.1 using the # symbol
  3. restart your mysql server once.

Update

In Step 1, if you cannot find bind-address in the my.cnf file, look for it in /etc/mysql/mysql.conf.d/mysqld.cnf file.

Update in case of MySQL replication enabled

Try to connect MySQL server on IP for which MySQL server is bind in 'my.cnfinstead oflocalhost or 127.0.0.1`.


Try localhost instead of 127.0.0.1 to connect or in your connection-config. Worked for me on a Debian Squeeze Server


This happens when you forget to start the database before connecting to it:

mysql.server start

then

mysql -u root -p -h 127.0.0.1

In my case (remote connnection) helped turning off firewall on server.

service iptables stop

This problem may occur because your MySQL server is not installed and running. To do that start command prompt as admin and enter command:

"C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\mysqld" --install

If you get "service successfully installed" message then you need to start the MySQL service. To do that: go to Services window (Task Manager -> Services -> Open Services) Search for MySQL and Start it from the top navigation bar. Then if try to open mysql.exe it will work.


look at the my.cnf file, if there contain [client] section, and the port is other than real listen port (default 3306), you must connect the server with explicit parameter -P 3306, e.g.

mysql -u root -h 127.0.0.1 -p -P 3306


if you are here with the same error message and you use docker - try to use the name of the DB service as a host.

services:
  app:
    blablabla
  db:
    blablabla
  

i mean, instead of:

127.0.0.1 or localhost

use:

db