Allowing MySQL access to MySQL Server in Amazon EC2 instance from remote host


Here in this post I am going to tell how I did allow remote access to MySQL server running in Amazon EC2 instance running Linux. I believe you are capable of installing MySQL server in your Amazon EC2 and  I also believe you have read my previous posts on 'Firewalls in Amazon EC2 ...'. This post will help you open the ports for the MySQL Server.
Now, connect to your Amazon EC2 instance and open mysql as a root user and then run the following SQL query:
 grant all on db_name.* to 'username'@'%';
This command will allow all the permission to the database db_name to the user 'username' from any host. That is the database can be accessed from any remote host. For you case please don't forget to change the datbase name and the username. Using % means to allow all hosts, if you have any specific host than please change that to what you want.
e.g.
 grant all on db_name.* to 'username'@'example.com';
Once you have granted the permission, now reload the permission privileges on mysql by the following SQL query:
flush priviliges
Now that we have granted permission to MySQL user to access the server from remote host. Let's configure the firewall to accept connection to the server.
Open /etc/sysconfig/iptables file and add the following line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
Restart the iptables service using the following command.
service iptables restart
Also from amazon  console, add inbound rule for port 3306 or the MySQL rule to the security group in use. If you are thinking how to do this then visit the post: "Firewalls in Amazon EC2 .."

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud