You are Here: FAQ ->Dedicated Servers->Root Server->HowTo...->Article #15


How do I enable remote connections to MySQL databases?


By default, 1&1 dedicated Root servers come with the MySQL remote access disabled. This is for security reasons, as it can be a security risk for the server. If you would like to enable this access, it is done at your own risk and 1&1 assumes no responsibility for any damages as a result of enabling this access.


Step 1: Firstly you will need to log into your server's shell via SSH.


Step 2: Once connected you need to open this file "/etc/my.cfg" this can be done using the command:

vi /etc/my.cnf


Step 3: You will see a few lines of text. Comment out the 'skip-networking' by first pressing 'i' on your keyboard to indicate you want to insert text and then preceding the line with a hash(#) sign.

[mysqld]
default-character-set=latin1
datadir=/var/lib/mysql
socket=/var/lib/mysq/mysql.sock
skip-innodb
#skip-networking

[mysql.server]
user=mysql
basedir=/var/lib
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


Step 4: Save and close the file (To exit vi while saving the changes press the Esc key to signify you want to type a command and the type ":x" without the quotes and press enter. To exit without saving press the Esc key to signify you want to type a command and type ":q!" without the quotes and press enter.)


Step 5: Now you will need to log into your MySQL Database via the shell you have open. To do this type the following command into the shell:

root@serverName:~$ mysql -u admin -p

This will log you into MySQL after prompting for a password. You will now see a MySQL prompt.


Step 6: Type the following at the MySQL prompt to select the mysql database:

mysql> use mysql;


Step 7: Next you will need to grant access to the database based on IP address. To do this use the the following commands, replacing the IP addresses and Database Names with the respective information. Please be sure to hit enter after every semicolon encountered as each line ending in a semicolon is a separate command.

mysql> update db set Host='123.123.123.123' where Db='yourdatabasename';
mysql> update user set Host='123.123.123.123' where user='yourdatabaseUsername';


Alternately you may specify to allow connections from any IP address by using the percent sign(%) which is a wildcard character in placement of the IP address like below:

mysql> update db set Host='%' where Db='yourdatabasename';
mysql> update user set Host='%' where user='yourdatabaseUsername';


Step 8: Logout of MySQL with the exit command and press enter.

mysql> exit


Step 9: Next restart the mysql database with the command :

root@serverName:~$ /etc/rc.d/init.d/mysqld restart


Step 9: You may now test the connection using telnet if you have telnet installed on your machine (Microsoft Windows Vista does not have telnet installed by default) by running the following line in a command prompt:

C:\Documents and Settings\userName> telnet 123.123.123.123 3306




Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5