Thursday, March 8, 2012

Remote access MySQL

Recently I come cross MySQL which I have not used much before. To connect it on localhost is without any issue till I want to move the MySQL to my EC2 instance.

To make the magic happen, 2 things need to check.

1. mysql only allows localhost to access by default.
If this step is missing the error below will happen.
ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx'
Fixing:

open mysql config file by    sudo nano /etc/mysql/my.cnf comment out the line    bind-address=127.0.0.1 and
skip-networking if existing
Or we can specify a ip say 10.0.0.2 for bind-address as a result only this ip 10.0.0.2 can access mysql. And only one ip can be bound!


2. Root user can not be used to log in remotely by default.
If this step is missing the error below will happen.
ERROR 1130 (HY000): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
Fixing:

Make sure to modify root user's privileges to allow remote user login mysql as root user. Don't recommend this way for security reasons. A better is to create another user and enable it to access mysql remotely.

No comments:

Post a Comment