Home  >  Article  >  Database  >  How to Connect to Specific MySQL Servers Through an SSH Tunnel?

How to Connect to Specific MySQL Servers Through an SSH Tunnel?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-04 15:01:02603browse

How to Connect to Specific MySQL Servers Through an SSH Tunnel?

SSH-Tunneled MySQL Connections: Connecting to Specific Servers

In a setup where multiple databases are hosted at different servers and require access through an SSH tunnel, connecting to the specific MySQL server "beyond" the tunnel can be challenging.

To establish the desired connection, it is crucial to specify the correct MySQL server when creating the SSH tunnel. This can be achieved by using the -L option in the SSH command. The syntax is as follows:

ssh -f [email protected] -L <local-port>:mysql1.example.com:3306 -N

In this example, a tunnel is created from local port 3307 to remote port 3306 at mysql1.example.com.

Once the tunnel is established, you can connect to the MySQL server via the 'mysql' command:

mysql -h 127.0.0.1 -P 3307

This command will correctly connect to the MySQL server at mysql1.example.com through the established SSH tunnel.

The above is the detailed content of How to Connect to Specific MySQL Servers Through an SSH Tunnel?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn