1

I want to be able to programmatically query the Amazon MySQL instance from my local server.

I have been able to setup MySQL workbench to use the ec2 server to create an ssh connection and then to connect to the MySQL server, so I can query the database through the workbench query window. But haven't been able to find a way to do the same using the command line tools?

user802599
  • 787
  • 2
  • 12
  • 35

1 Answers1

0

Use an SSH client (ssh on Linux/OSX or PuTTY on Windows) to connect via SSH into your AWS instance. Then, navigate to the directory where the MySQL command-line utility (mysql) is stored (presumably in usr/bin). Log in like so:

mysql -h localhost -u [USERNAME] -p [PASSWORD]

mysql is the MySQL command-line utility. The -h (host) option is set to localhost since you're already operating from the AWS instance, and I am assuming that your MySQL installation is on the same server. The -u and -p options are self-explanatory (username and password).

nb1987
  • 1,400
  • 1
  • 11
  • 12
  • I have tried using PuTTY and I can use it to setup a connection to the EC2 server instance but I need to pass through the ec2 instance and connect to the RDS instance. Running mysql and passing in the RDS host name just gives me 'Unkown MySQL server host ...' I need to know how to tell mysql to connect to the ec2 instance first and then the RDS instance. – user802599 Mar 14 '14 at 16:00
  • Hm, it's not quite clear to me...do you have an RDS instance running (in which case I would say connect to that directly -- see the AWS documentation at http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html ), or do you have a MySQL database running on your EC2 instance? (If the latter, you may find it easiest if you can connect without key but just username/password -- see http://stackoverflow.com/questions/6119774/ssh-to-aws-instance-without-key-pairs) In any scenario you would also need to be sure that your security groups allow you to access the DB remotely. – nb1987 Mar 14 '14 at 17:30
  • I have an RDS instance and have tried the direct connection that you linked to the documentation for but just get Error 10060. But I have the VPC security groups setup to allow connections from my current IP on the MySQL port(3306). – user802599 Mar 16 '14 at 23:33