Home > Database > Mysql Tutorial > body text

How to Specify a Target MySQL Server When Using SSH Tunneling?

Mary-Kate Olsen
Release: 2024-11-06 07:46:02
Original
701 people have browsed it

How to Specify a Target MySQL Server When Using SSH Tunneling?

SSH Tunneling to a Specific MySQL Server

MySQL users often face the challenge of securely accessing multiple databases hosted on distinct servers through an SSH tunnel. The query arises: how to specify a target MySQL server when using an SSH tunnel?

To establish the tunnel, a tool like autossh can be utilized on a Debian-based web server. However, simply setting up the tunnel may not suffice. The key lies in specifying the MySQL server to be accessed during the tunnel's creation itself.

The following command addresses this issue:

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

Replace "[email protected]" with the SSH host credentials, "mysql1.example.com" with the desired MySQL server hostname, and change "3307" and "3306" with the relevant SSH and MySQL ports.

Once the tunnel is established, connecting to the specified MySQL server becomes straightforward:

mysql -h 127.0.0.1 -P 3307
Copy after login

This modified approach ensures a successful connection to the intended MySQL server through the SSH tunnel.

The above is the detailed content of How to Specify a Target MySQL Server When Using SSH Tunneling?. 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!