简体   繁体   中英

MySQL Database Connection via SSH Tunnel

i have a problem with our new database. The only way to access the database is throw a SSH tunnel. But it doesn't work...

I use following commands:

sshpass -p <PASSWORD> ssh <USER>@<DOMAIN> -p <PORT> -L 3306:localhost:3306 -f -N

I think the ssh tunnel works and is established.

Now I want to connect via Shell-File the database.

deposit=`mysql -h localhost --port=3306 -u <DATABASEUSER> --password=<DATABASEPASSWORD> --skip-column-names -e "<MYSQLSYNTAX>"`

But there is always folowing error:

ERROR 1045 (28000): Access denied for user '<DATABASEUSER>'@'localhost' (using password: YES)

Do you have any ideas or am I doing something wrong?

Thank you very much!

Assuming all your permissions are okay, it may be worth swapping localhost for 127.0.0.1 .

As per the MySQL docs: http://dev.mysql.com/doc/refman/5.5/en/connecting.html

On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server.

As I understand you are trying to create a tunnel between your computer and a remote computer that's running SQL server. In your ssh command substitute 3306:localhost:3306 with the remote computer IP address. Note this should be its internal local IP address if you are not in the same local network as the remote computer. Check your SQL Database permissions, username and password as well.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM