Web App Development

Connecting to an EC2 MySQL server remotely

After setting up MySQL server in the previous post it will only accept connections from other programs on the server. Follow the steps below to access it from your development computer.

Updating EC2 security groups

By default EC2 instances don't allow traffic on port 3306, which is used by MySQL. So we need to add an exception to the inbound traffic rules:

Granting remote access in the MySQL security settings

First log in to MySQL as root:

mysql -u root -p

We can run this query to grant remote access to all tables in the database:

grant all on *.* to root identified by 'pw';
flush privileges;
exit

Connecting remotely

To log in run mysql and pass the public server address as the host-name (-h):

mysql -u root -h public-dns.compute-1.amazonaws.com -p

Or use MySQL Workbench:





Comments


Follow me on Twitter