Enable remote access to your MySQL Database on CentOS 6

Often you’ll need some remote access to your database in order to retrieve or manage data.

This can be set up quite easy.
First step would be to allow the network to access the mysql service. This is done by editing the /etc/my.cnf configuration file.
nano /etc/my.cnf
Now look for the line which contains # skip-networking and uncomment it.
Save the configuration file and restart the mysql service.

service mysqld restart

Now that you just allowed network access to your MySQL server you probably need to assign some credentials for remote access.
First login to your db:

mysql -u root -p mysql

Then you’re ready to create a database:

mysql> CREATE DATABASE database;

create a username for remote access:

mysql> GRANT ALL ON database.* TO user@’host’ IDENTIFIED BY ‘PASSWORD’;

or grant access to an already existing database:

mysql> update database set Host=’′ where Db=’database’;
mysql> update user set Host=’′ where user=’admin’;
Note: to grant access to any host use the wildcard ‘%’ instead of a host name/ host ip.

Leave a Reply

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