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, 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 =

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

sudo /etc/init.d/mysql restart


  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.


  2. Matt Todd says:

    Totally not related, but check this out: http://railsforphp.com/reference

    You can search for the Ruby equivalent to PHP functions, like http://railsforphp.com/array or http://railsforphp.com/fopen etc.

    Also, http://code.google.com/p/rtunnel/ may be of interest to you.

    Matt Todd


  3. Mr Frosti says:

    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.


Leave a Comment

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.