Allow remote connections to your MySQL server

Before we begin

You will be glad to know, assuming you have MySQL up and running, there is no installation necessary for this task. You will need access to the MySQL administrators password as well as administrative access so you can edit a MySQL configuration file. Other than that simple necessity (and a terminal window), you are ready to get cracking.

Editing my.conf

Before you actually start editing the /etc/mysql/my.conf file, I would suggest you back up your current file. Do this with the command:

sudo cp /etc/mysql/my.conf /etc/mysql/my.conf.bak

Now that the file is backed up let’s open this baby up for editing. When you have the file open you are going to want to look for this line:

bind-address = 127.0.0.1

What the above line does is limit connections to the localhost and only the localhost. You want to comment this line out by changing it to:

#bind-address = 127.0.0.1

Now save that file and restart MySQL with the command:

sudo /etc/init.d/mysql restart

When MySQL has restarted you now need to get to the MySQL command prompt.

The mysql prompt

In order to get to the mysql prompt you will want to issue the command:

mysql -u root -p

Where root is the MySQL administrative user (most like it is root).

You will be prompted for the MySQL administrators password. After you have successfully authenticated you will have a new prompt that looks like:

mysql>

You are now at the MySQL prompt. You only have one command to enter for this to work. You will want to enter this command carefully:

GRANT ALL PRIVILEGES ON *.* TO username@address IDENTIFIED BY “password”;

Where username is the username on the remote machine that will be connecting, address is the IP address of the remote machine, and password is the password that will be used by the remote user.

When that command is issued successfully you should see something like:

Query OK, 0 rows affected (0.00 sec)

As long as you get Query OK, you should be good to go.

Now when you need to connect from a remote machine you will use the IP address of the MySQL server, the username you entered in the MySQL command prompt, and the username will be the username you entered in the MySQL command prompt.

That’s it. Your MySQL server is ready to accept remote connections.

Final thoughts

It should go without saying that you will also want to make sure this MySQL server is protected with a good firewall

By Lu Jun

80后男,就职于软件行业。习于F*** GFW。人生48%时间陪同电子设备和互联网,美剧迷,高清视频狂热者,游戏菜鸟,长期谷粉,临时果粉,略知摄影。

Leave a comment

Your email address will not be published. Required fields are marked *

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