Enable access from other hosts to a MySQL server
Recently I deployed a MySQL server. But there was a problem that I could not access the data base from a application which was hosted in another server. The reason for this is by default MySQL server does not accepts requests from other hosts except the localhost.
To solve this problem we have to do two tasks.- Create a user which has permissions to read and write to a database from a different host
GRANT ALL PRIVILEGES
ON database.*
TO ‘user’@'yourremotehost'
IDENTIFIED BY 'newpassword';
As an exmaple following query enables root user to access all the databases from any host.
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
- Bind the ip adress
There you can find an entry like
bind-address = 127.0.0.1
If you want to enable access from all the host just remove it. If you want to limit the hosts you can add entries like
bind-address = your ip
After doing that you have to restart the MySQL server. In Ubuntu you can do that like below.
sudo /etc/init.d/mysql restart
Comments
Post a Comment