Can not connect to mysql server 111?

When I want to build connections between database and Python programs with SQLAlchemy on Google Colab, it occurs errors saying: (mysql.connector.errors.InterfaceError) 2003: Can’t connect to MySQL server on ‘localhost:3306’ (111 Connection refused) and Can’t connect to MySQL server on ‘localhost:3306’ [Errno 99] Cannot assign requested address.

Here’s my solution. It can also be understood as to how to allow remote MySQL database connection.

Step1. Modify bind-address

sudo vim /usr/local/etc/my.cnf

While the location of ‘bind-address’ in files is not fixed, it may summarize are:

  1. /etc/mysql/mysql.conf.d/mysqld.cnf

2. /etc/mysql/mariadb.conf.d/50-server.cnf

3. /etc/mysql/mysql.conf.d

4. /etc/mysql/mariadb.conf.d

5. /etc/mysql/my.conf

…….

Can not connect to mysql server 111?

In this .cnf, the mission is to replace ‘bind-address = 127.0.0.1’ by ‘bind-address = 0.0.0.0’.

First, ‘Ctrl + v’ to enter —VISUAL BLOCK — mode. Use arrow keys to select lines that need to be adjusted.

Secondly, press ‘Shift+i’ to enter insert mode. That’s to say we will comment out the line ‘bind-address = 127.0.0.1’ with ‘#’ and insert a new line ‘bind-address = 0.0.0.0’.

Can not connect to mysql server 111?

After done all the modifications, press ‘ESC’ to change mode, then input:

  1. :w- save files, not exit from vim

2. :w file- save the changes as a new file, not exit from vim

3. :wq- save files and exit

Before the next step, check the changes do exits in target files.

Step2. Restart MySQL Server

service mysql start

Step3. Create new users to visit remotely

mysql -u root -p

Then we will need to add a user to access the database.

grant all privileges on *.* to root@"%" identified by ".";

The above code, which you might find the most common, will lead to ERROR 1064 (42000). Because MySQL 8.0 hasn’t supported this method anymore.

The correct way is:

CREATE USER 'user'@'xx.xx.xx.xx' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database’s name.* to 'user'@'xx.xxx.xx.xx' ;
FLUSH PRIVILEGES;
ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'password';FLUSH PRIVILEGES;

If you want the user to manage all databases, use ‘*’ as database_name.

If you want to connect from anywhere, replace ‘xx.xx.xx.xx’ with ‘%’.

For example,

Can not connect to mysql server 111?

Question

Ubuntu 14.04 x32.

Installed php, phpmyadmin, apache, mysql.

Created database, upload my website files and I’m getting this error message:

Connect Error (2003) Can’t connect to MySQL server on ‘myipaddress’ (111)

I tried these solutions:

  1. In etc>mysql>my.cnf change these line: secure.bind-address=127.0.0.1 to secure.bind-address=myipaddress Didn’t work.

  2. mysql> GRANT ALL ON mydbname.* TO root@‘myipaddress’ -> IDENTIFIED BY ‘mymysqlpassword’;

It did’nt work, too.

What can i do sometimes?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Why MySQL server is not connecting?

Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.

How do I fix MySQL host is not allowed to connect to this server?

To fix this, add a user that allows your host. To allow any host, use the wildcard symbol %. You can add a user from the command line or with a UI client (such as MySQL Workbench or phpMyAdmin). I'll show an example below of adding a user that allows any host.

Can't connect to MySQL server on remote host?

To allow remote access to MySQL, you have to comment out bind-address (you did) and skip-networking in the configuration file. Next, you have to make sure the user is allowed remote access. Check your user with this: SELECT User, Host FROM mysql.

How do I fix MySQL server error?

Check the error log to see why the server does not start. ... .
Specify any special options needed by the storage engines you are using. ... .
Make sure that the server knows where to find the data directory. ... .
Make sure that the server can access the data directory..