Practical Web Programming

Tuesday, February 18, 2014

How to enable remote access in a MySQL server

Let say you are developing locally and wanted to connect to a remote mysql server for testing, if that remote server is not configured to allow access from a different machine, you won't be able to connect to it. Assuming you want to allow 'the_user' user to connect remotely, here's to do it. 

Edit your my.conf file (usually located at /etc/mysql/ folder), and change the bind-address value 

from: bind-address = 127.0.0.1
to:     bind-address = 0.0.0.0

Login as a root user to MySQL. If you don't have the password run this command:

sudo mysql --defaults-extra-file=/etc/mysql/debian.cnf

Once you are logged in, run these commands

USE mysql;
UPDATE user SET host='%' WHERE User='the_user';
UPDATE db SET Host='%' WHERE User='the_user';
FLUSH PRIVILEGES;

Then, restart mysql

sudo service mysql restart

0 comments:

Recent Post