Basic steps to use Mysql SSH tunnel connection

Basic steps to use Mysql SSH tunnel connection

Preface

For security reasons, the root user of MySQL can only log in locally and does not have authorized access to the external network. At this time, you can connect to the MySQL database through the SSH tunnel. The following are the basic steps to configure a Mysql SSH tunnel connection.

Let's take a look at the detailed steps.

Deleting Remote Login

Log in to mysql:

 mysql -uroot -p

View the user's open access permissions:

select user, host from mysql.user;

Remove unnecessary access permissions, such as:

delete from mysql.user where user='root' and host='%';
flush privileges;

Query again to verify whether the deletion is successful.

Establishing a Tunnel

The server can be logged in by username and password or RSA key. It is recommended to use RAS key and place the local id_rsa.pub content in ~/.ssh/authorized_keys of the server. How to generate RSA key is not described here.

Open a separate window, modify the IP and port corresponding to the following command and execute it:

ssh -NCPf [email protected] -L 3388:127.0.0.1:3306

Parameter explanation:

  • C Use compression, which is optional and speeds up.
  • P Use a non-privileged port for outgoing connections.
  • f After SSH completes authentication and establishes port forwarding, it goes into the background.
  • N Do not execute the remote command. This parameter is useful when only forwarding ports are opened (supported by SSH V2)

[email protected] is the SSH username and IP address for logging into the MySQL server. -L 3388:127.0.0.1:3306 means opening a mapping from port 3388 on the local machine to port 127.0.0.1:3306 of the MySQL server. 127.0.0.1 can also be the intranet or extranet IP address of the server where MySQL is located.

Then, use the mysql tool to enter the corresponding username and password to log in. Note that when logging in, the host address selected is localhost or 127.0.0.1. At the same time, open the access rights of the corresponding IP in the MySQL database.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • How to use ssh tunnel to connect to mysql server
  • Solution to slow intranet ssh/mysql login
  • How to install MySQL via SSH on a CentOS VPS

<<:  An Uncommon Error and Solution for SQL Server Full Backup

>>:  Docker data management and network communication usage

Recommend

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

Two methods to stretch the background image of a web page

There are two solutions: One is CSS, using backgro...

Solve the Linux Tensorflow2.0 installation problem

conda update conda pip install tf-nightly-gpu-2.0...

How to set the height of the autosize textarea in Element UI

After setting textarea input in Element UI to aut...

Detailed explanation of MySQL group sorting to find the top N

MySQL group sorting to find the top N Table Struc...

Explanation on whether to choose paging or loading in interactive design

The author of this article @子木yoyo posted it on hi...

In-depth explanation of slots and filters in Vue

Table of contents Slots What are slots? Slot Cont...

Detailed steps to install Docker mongoDB 4.2.1 and collect springboot logs

1: Install mongodb in docker Step 1: Install mong...

How to install and modify the initial password of mysql5.7.18 under Centos7.3

This article shares with you the installation of ...

Bootstrap3.0 study notes table related

This article mainly explains tables, which are no...

Website User Experience Design (UE)

I just saw a post titled "Flow Theory and Des...

How to use javascript to do simple algorithms

Table of contents 1 Question 2 Methods 3 Experime...