Home >Database >Mysql Tutorial >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
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
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!