anna
anna

Reputation: 662

how to write a script for connecting to mysql by TCP/IP over SSH?

As shown in the title, I want to open mysql at my local terminal. I wrote 2 lines:

ssh -i pem user@1.1.1.1   #Log in to server with password
mysql -h xxx -u user -p  #connect to MySQL with password

Is it possible to make it in one line? Or Can I write it in a script? Really fresh on Bash:)

Upvotes: 0

Views: 128

Answers (1)

Zilicon
Zilicon

Reputation: 3860

Last part of ssh's synopsis in the man page is [command].

Since mysql is a screen based program you need to run ssh with -t

This should work:

ssh -t -i pem user@1.1.1.1 "mysql -h xxx -u user -p"

Upvotes: 1

Related Questions