Detailed explanation of MySQL remote connection permission

Detailed explanation of MySQL remote connection permission

1. Log in to MySQL database

mysql -u root -p

View the user table

mysql> use mysql;
Database changed
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)

You can see the root user that has been created in the user table. The host field indicates the host being logged in. Its value can be either IP or host name.

(1) If you want to log in using your local IP address, you can change the Host value to your own IP address.

2. Realize remote connection (authorization method)

Changing the value of the host field to % means that you can log in to the MySQL server as the root user on any client machine. It is recommended to set it to % during development.
update user set host = '%' where user = 'root';

Change the permissions to ALL PRIVILEGES

mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)

This way the machine can remotely access MySql on the machine with the username root and password root.

3. Realize remote connection (table modification method)

use mysql;

update user set host = '%' where user = 'root';

In this way, you can access Mysql remotely through the root user.

4. If the above method does not work

This may be caused by the access to port 3306 restricted by the corresponding server. The following is an example of Tencent Cloud:

Only by opening port 3306 can the connection be successful!

The above is the detailed explanation and integration of MySQL remote connection permissions introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of MySQL user and permission management
  • Detailed explanation of the process of querying user permissions using mysql statements
  • MySQL users and permissions and examples of how to crack the root password
  • In-depth explanation of MySQL user account management and permission management
  • The easiest way to create a new user and grant permissions to MySQL

<<:  Using puppeteer to implement webpage screenshot function on linux (centos)

>>:  Analysis of the implementation principle of Vue instructions

Recommend

How to limit the number of records in a table in MySQL

Table of contents 1. Trigger Solution 2. Partitio...

Sample code for implementing menu permission control in Vue

When people are working on a backend management s...

Detailed explanation of Linux netstat command

Table of contents Linux netstat command 1. Detail...

How to monitor array changes in Vue

Table of contents Preface Source code Where do I ...

Common scenarios and avoidance methods for index failure in MySQL

Preface I have read many similar articles before,...

Summary of some tips for bypassing nodejs code execution

Table of contents 1. child_process 2. Command exe...

Vue implements image dragging and sorting

This article example shares the specific code of ...

jQuery+Ajax to achieve simple paging effect

This article shares the specific code of jquery+A...

Introduction to Docker containers

Docker Overview Docker is an open source software...

Summary of commonly used tags in HTML (must read)

Content Detail Tags: <h1>~<h6>Title T...

Use a table to adjust the format of the form controls to make them look better

Because I want to write a web page myself, I am al...

How to upgrade MySQL 5.6 to 5.7 under Windows

Written in front There are two ways to upgrade My...