Connecting to MySQL from a Remote Location

The most common way to work with and manage MySQL is directly, using the command line or a web-based tool such as phpMyAdmin.  If, however, you have more than one database server or need to do routine complex tasks, the former may be too tedious, and the latter may be too simple.  Another possible reason for connecting remotely is that your database server is on a different physical machine from your web server.

Using a graphical tool like MySQL Administrator or a tool from a third-party vendor, you can opt to manage your database remotely, without being connected directly to the server.  On a Linux server, you typically cannot do this by default, as opening up MySQL to any remote connections is a big security risk.  To allow remote access, make the following changes.

1. As root, edit the my.cfg file using a text editor.

vi /etc/my.cnf

2. Find the section labeled [mysqld] and locate the line “skip-networking”.  If it is not commented out, add a “#” in front of it to do so.

# skip-networking

3. Add the following line with your own IP address, the one you want to connect to the databases ( is just an example):

bind-address =

4. Save the file and exit.

5. Restart mysql:

/etc/init.d/mysql restart

6. You must grant remote access to the specific databases you want to manage remotely.

mysql -u root -p mysql

mysql> CREATE DATABASE dbname;

mysql> GRANT ALL ON dbname.* TO user@’’ IDENTIFIED BY ‘PASSWORD’;

You can also do the same thing through phpMyAdmin and even grant access to multiple databases.  You should also make sure your firewall will allow remote access to the MySQL port number 3306.