Tuesday, March 15, 2011

Enable Remote Access To MySQL Server

1, update my.cnf to make it liston to ip address, not localhost

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
bind-address = 6.31.83.19

2, Save the file and Restart the mysql server, enter:
# /etc/init.d/mysql restart

3, Update your mysql database user privileges
A: If you want to update existed account, you may do:
mysql> update user set Host='%' where user='greg';
mysql> flush privileges ;

Host='%' means allow user greg access this mysql server from any IP address.
If you want a specified IP, you can do
mysql> use mysql
mysql> update user set Host='6.6.6.6' where user='greg';
mysql> flush privileges ;

B, Or you can use grant
mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO greg@'6.6.6.6' IDENTIFIED BY 'PASSWORD';
mysql> flush privileges ;

You don't need to restart mysql for step 3

No comments:

Post a Comment