Home > Database > Mysql Tutorial > How to Connect to a Specific MySQL Server Through an SSH Tunnel?

How to Connect to a Specific MySQL Server Through an SSH Tunnel?

Barbara Streisand
Release: 2024-11-04 09:26:30
Original
601 people have browsed it

How to Connect to a Specific MySQL Server Through an SSH Tunnel?

Connecting to a Specific MySQL Server Through an SSH Tunnel

When managing multiple databases hosted at different locations, it may be necessary to access them through an SSH tunnel. While creating the tunnel is straightforward, connecting to a specific MySQL server beyond the tunnel can be confusing.

To specify the MySQL hostname after establishing the SSH tunnel:

Modify the SSH Tunnel Command:

When creating the SSH tunnel, include the desired MySQL hostname as an additional parameter. For example:

ssh -f [email protected] -L 3307:mysql1.example.com:3306 -N
Copy after login

In this command, the tunnel is being forwarded to port 3307 on the local machine and then to port 3306 on the mysql1.example.com server.

Connect to the MySQL Server:

Once the tunnel is created, use the following command to connect to the MySQL server:

mysql -h 127.0.0.1 -P 3307
Copy after login

By specifying 127.0.0.1 as the host and 3307 as the port, the MySQL client will connect to the localhost port 3307, which is the local end of the SSH tunnel. This will then forward the connection to the mysql1.example.com server.

The above is the detailed content of How to Connect to a Specific MySQL Server 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