I checked other threads but couldnt find an answer for this specific question.
To make things easier, here is the setup I use to connect to db using mysqlworkbench
ssh hostname :somehostname.com:22
ssh username: ec2-user
ssh password : my private key password
ssh keyfile /Users/me/.ssh/id_rsa : this is my private key stored on my local machine
mysql hostname: qa.cbhasfasupvz.us-east-1.rds.amazonaws.com
port: 3306
username: root
passowrd : mysql database password
my public key is set on the server already and I can connect to the database through mysqlworkbench.
But i need to connect to this database using the private key I have, from another server through php. So i can make some queries and present them in html tables etc.
My guess is to create a php file on my server, store my private key somewhere on this server safely. connect to database using the private key, db location, password etc.
I am asking the connection code I need in that php file. This is what I would use if the db was located on the local server
mysql_connect("localhost", "root", "pass") or die(mysql_error()) ;
mysql_select_db("my_db") or die(mysql_error()) ;
If you wanna connect to the server remotely,use this command
ssh -i private_key_file.cert user@host
and then connect to your mysql using
mysql -u user -p
which prompts you to insert your password.
Practically, when you're connected like this,you can do whatever you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.