Allowing MySQL on Amazon’s EC2 to accept remote connections
Hello, This blog is moving over to www.whoisthestudent.com. More Amazon EC2 articles to come!
Hopefully see you there!
Amazon’s EC2 is a really great platform for well, everything!
I recently got a LAMP server setup some development, instead of having a LAMP server running locally. It is always a nice idea to see your code in an actual production environment, not local setting.
One little hitch people will come across after setting up a LAMP server on the EC2, is how do you allow remote connections to your mysql database.
It is actually really simple, just a few small extra steps are needed!
Ok, it’s get started…
- Head over to your myself configuration. file. located at /etc/mysql/my.cnf and look for the “bind-address” this should have a value of 0.0.0.0
- Restart your mysql server
- Next we need to open the port on the EC2. Log into your user account and on the left hand side, head down to “Security Groups“. Look for the security group that is associated with your EC2 instance. (You can find the name of the security group for your instance to the right hand side of the instance name on main instance listing page). Once you have found the security group, click on it and under the “Inbound” tab you will see a list of port rules for the inbound traffic.Here you can open the MySQL Port (3306 by default unless you changed it). You will see a list of predefined ports for services that you can select to quickly add. Once of these is for MySQL (Others include HTTP, SSH etc).Don’t forget to click “Apply Rule Option” at the bottom when you are finished.
- Finally, we need to make a non “root” user account that will be used to access the database remotely. To access mysql from the terminal type: mysql -u root -pAnd you will then be prompted for your password. Once you have opened MySQL run the following command: GRANT ALL PRIVILEGES ON *.* TO bob@’%’ identified by “yourpasswordhere”;By running this command, you will be giving access to a user called bob, with the password yourpasswordhere and it will be accessable from any location.
And your done!