Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: connection refused when trying to connect to localhost using remote IP

Tags:

mysql

When I try to connect to a local mysql database using it's remote ip-address I get a access denied. When I try to connect to that same database from an external machine, it works without any problems. When I connect to the local database using localhost, it works perfectly as well. E.g., if the database server has the ip 1.2.3.4 then I get the following results:

# From the db server
mysql -u username -h localhost -p #works perfectly
mysql -u username -h 127.0.0.1 -p #works perfectly
mysql -u username -h 1.2.3.4 -p #Access denied

# From any other machine
mysql -u username -h 1.2.3.4 -p #works perfectly

What can I do to allow local access to my database using its remote ip-address? The OS of the database server is Fedora 15 and the MySQL version is 5.5.23.

like image 531
Tiddo Avatar asked Oct 23 '12 14:10

Tiddo


People also ask

How do I fix MySQL connection refused?

Check that the DB username, DB password, database host, and database port are correct. (if you are unsure, reach out to your database administrator or check in your web hosting account for the up to date credentials). If the config file references host = "localhost" , you can try to change it to 127.0.

How do I connect to a MySQL database using IP address?

Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed. Note: The IP address of the instance and the mysql client IP address you authorize must be the same IP version: either IPv4 or IPv6. Click Done.

How do I allow remote connections to MySQL from specific ips only?

To do so, you need to edit the MySQL configuration file and add or change the value of the bind-address option. You can set a single IP address and IP ranges. If the address is 0.0. 0.0 , the MySQL server accepts connections on all host IPv4 interfaces.


1 Answers

Try to edit/add bind-address = 0.0.0.0 to your [mysqld] section of your /etc/mysql/mysql.conf.d/mysqld.cnf file and restart MySQL Service.

like image 178
Eduardo Cuomo Avatar answered Sep 28 '22 07:09

Eduardo Cuomo