Computers, Linux, Open-source, Software, Web, Windows

Ubuntu: connect to MySQL from remote host

Just a quick gotcha that I always stumble upon in Ubuntu. By default, the MySQL database is set only to listen to requests on the localhost (for security reasons). If you want to connect to the database remotely, say using MySQL Admin GUI Tools, you will need to make a quick change.

First run this to edit the MySQL config file with root permissions:

sudo vim /etc/mysql/my.cnf

Next, look for the property “bind-address” (press “/” in VIM to start a search). In Ubuntu server 7.04 it is on line 47 but this is total subject to change. Instead of it reading 127.0.0.1, change it to the static IP of the server. In most *nix distributions, this can be found by running “ifconfig”. My server configuration line now looks like this:

bind-address = 168.28.245.99

All that remains is to give the MySQL database a quick restart to apply the change:

sudo /etc/init.d/mysql restart
Advertisements

3 thoughts on “Ubuntu: connect to MySQL from remote host

  1. `GRANT ALL PRIVILEGES ON *.* TO newuser@”%” IDENTIFIED BY ‘newpassword’;`

    No need to change the bind-address. If you want to restrict the user to a specific IP just change the % to the IP address. Or `newuser@”192.168.1.%”` etcetera.

    Like

  2. I tried the newuser@”%” method, but report it didn’t work for me. Only after I had changed the bind parameter in the configuration file did it have the expected result.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s