Home > Database > Mysql Tutorial > body text

How to Connect to a Specific MySQL Server via SSH Tunnel?

Patricia Arquette
Release: 2024-11-05 10:58:02
Original
860 people have browsed it

How to Connect to a Specific MySQL Server via SSH Tunnel?

Connecting to a Specific MySQL Server via SSH Tunnel

Connecting to multiple MySQL databases hosted at different addresses through an SSH tunnel can be a cumbersome task. This becomes apparent when attempting to specify a particular MySQL server after creating the tunnel.

To overcome this challenge, it's crucial to understand that the SSH tunnel should be established while connecting to the desired MySQL host. The following command demonstrates this process:

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

By specifying mysql1.example.com:3306 in the -L flag, the tunnel is configured to forward port 3307 on the localhost to port 3306 on the intended MySQL server.

Once the tunnel is established, connecting to the MySQL server is as simple as:

mysql -h 127.0.0.1 -P 3307
Copy after login

This command should now successfully establish a connection to the specified MySQL host, allowing you to access the database as intended.

The above is the detailed content of How to Connect to a Specific MySQL Server via 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!