Quick overview of the actions you need to do:
- Edit /etc/mysql/my.cnf in the ec2 server to allow connections from outside. Some installations only allow localhost. Restart mysqld server.
- Open port 3306 from AWS console, giving access to your IP. Make sure you can connect using "telnet IP-address 3306". You need to see the same stuff than doing telnet localhost 3306 from the ec2 machine.
- Create/modify mysql user so that it can connect from outside. Some mysql installations create a root@localhost user, but this is a different user from root@your-IP. Check that, and then doublecheck using the mysql command you wrote above.
- Eval the code below in emacs and then do
M-x sql-connect
Emacs should prompy you for a database to conect. Just type "test" (emacs will autocomplete)
(setq sql-connection-alist
'(("test"
(sql-product 'mysql)
(sql-database "your-db-name")
(sql-server "your-ec2-ip")
(sql-user "user-name")
(sql-password "password"))))