Using ssh tunnel to connect to the mysql server, sshtunnel

Source: Internet
Author: User

Using ssh tunnel to connect to the mysql server, sshtunnel

Preface

In some cases, we can only know the Intranet address of the database and cannot connect to the database through the Intranet. However, we can log on to other machines on the same Intranet and these machines can access the database through the Intranet, then we can access the database through ssh tunnel.

Usage

The usage of ssh tunnel is very simple. The specific format is as follows:

Ssh-L [local port]: [remote host]: [remote port] [username] @ [remote host]

Use-LTo access the local port through ssh tunnel and forward to the port of the remote host. In actual use, we can add the-f and-N parameters to make the ssh command work in the background without executing any command.

Practice

Assume that the Intranet ip address of our mysql server is 10.86.22.22 and port 3306 is enabled. The Internet ip address of another server in the same Intranet as mysql is 121.43.23.12.

Run the following command locally:

$ Ssh-f-N-L 12345: 121.43.23.12: 3306 root@121.43.23.12

Then run the following command locally:

$ Mysql-u root-P 12345-h 127.0.0.1-p

After entering the password, you can log on to mysql.

After the execution, we can find the sshd connection we just created through ps, and kill it to close the ssh tunnel we just created.

Summary

The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.