Home > Database > Mysql Tutorial > body text

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

Mary-Kate Olsen
Release: 2024-11-04 15:01:02
Original
602 people have browsed it

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template