How to enable remote access to a MySQL database server
Posted April 1st, 2009 in MySql
MySQL is often configured to be accessible from the local host only. Recently I moved all my websites from a CentOS box to a Debian one and needed to be able to connect to the MySQL server on the new box from the old one, but was not able to. This post looks at how to enable MySQL to be accessible from remote servers.
The MySQL configuration file is at /etc/mysql/my.cnf on Debian and similar distros and /etc/my.cnf on CentOS, Red Hat Enterprise Linux and similar. It contains a bind-address setting which is often set as follows by default:
bind-address = 127.0.0.1
This binds the MySQL deamon to 127.0.0.1 which is the local machine and means it will not be able to be accessed from other machines, whether or not the firewall and/or privilege grant options allow it.
To allow it to be accessible from any host, comment the line out as shown in the following example and then restart MySQL:
#bind-address = 127.0.0.1
Note that you could set the IP address to that of the server but it will mean all connections to the MySQL server must be via that IP address as it is not currently possible to bind MySQL to more than one IP address. It's simply easier to comment the line out.
You'll still need to enable access to the MySQL server through the firewall from the remote server(s) and add/modify the appropriate permissions to the privileges tables and then you'll be good to go.
Related posts:
- How to change the storage engine a MySQL table uses (Saturday, January 17th 2009)
- Setting the MySQL timezone per connection (Saturday, December 20th 2008)
- How to update the max_connections setting in MySQL (Wednesday, December 10th 2008)
- Renaming a table in MySQL (Wednesday, July 2nd 2008)
- Reset the auto increment value for a MySQL table (Saturday, June 28th 2008)
- Showing running queries in MySQL (Tuesday, February 19th 2008)
Share or Bookmark
Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.
Subscribe or Follow
Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

