How to authorize remote connections in MySQL in Linux

How to authorize remote connections in MySQL in Linux

Note: Other machines (IP) cannot connect to the MySQL database through the client without authorization. If you need to remotely connect to MySQL on the Linux system, you must authorize the IP and specific user. Generally the root user is not available to developers. For example, if you want to use the SQLyog graphical management tool on Windows to connect to a MySQL database on Linux, you must first authorize it.

1. Log in to the MySQL database using the root user in the virtual machine

mysql -u root -p

Note: The root user password is usually set to root

2. Use the mysql command to authorize the mysql remote connection service for the root user

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

Description: This command is used to authorize the root user whose password is root and IP (%) is arbitrary. (%: fuzzy query, all IPs are acceptable, other host IPs can be specified; the 'root' after BY is the password)

3. Write the configuration into the mysql authorization table

mysql> flush privileges;

Modify the user table of the mysql database and change the host item from localhost to %. %This means that any host is allowed to access. If only a certain IP is allowed to access, you can change it to the corresponding IP. For example, you can change localhost to 192.168.1.123, which means that only the IP 192.168.1.123 in the local area network is allowed to remotely access MySQL.

mysql>use mysql; 
mysql>update user set host = '%' where user = 'root';
mysql>select host,user from user;
mysql> flush privileges;

Supplement: Open port 3306 in the firewall

1. Open the firewall configuration file

vi /etc/sysconfig/iptables

2. Add the following line

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

3. Restart the firewall

service iptables restart

Note: The statement to open port 3306 must be placed before icmp-host-prohibited

Attachment: Personal configuration

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solve the problem of error 10038 when connecting to MySQL remotely in Navicat
  • Detailed explanation of Navicat's slow remote connection to MySQL
  • How to install MySql in CentOS 8 and allow remote connections
  • Tutorial on installing MySQL with Docker and implementing remote connection
  • Solution to the problem that Navicat cannot remotely connect to MySql server
  • How to solve the 10060 unknow error when Navicat remotely connects to MySQL
  • Docker deploys mysql to achieve remote connection sample code
  • Navicat remote connection to MySQL implementation steps analysis
  • Tutorial on installing MySql5.7 in CentOS7.2 and enabling remote connection authorization
  • How to enable MySQL remote connection

<<:  Vue Beginner's Guide: Creating the First Vue-cli Scaffolding Program

>>:  Simple summary of tomcat performance optimization methods

Recommend

How to modify the scroll bar style in Vue

Table of contents First of all, you need to know ...

Detailed examples of ajax usage in js and jQuery

Table of contents Native JS How to send a get req...

JS implements circular progress bar drag and slide

This article example shares the specific code of ...

Three Ways to Find the Longest Word in a String in JavaScript (Recommended)

This article is based on the Free Code Camp Basic...

Packetdrill's concise user guide

1. Packetdrill compilation and installation Sourc...

Vue implements the browser-side code scanning function

background Not long ago, I made a function about ...

Install centos7 virtual machine on win10

1. Download VMware Workstation 64 version https:/...

How to bypass unknown field names in MySQL

Preface This article introduces the fifth questio...

Detailed explanation of MySQL slow queries

Query mysql operation information show status -- ...

Graphic tutorial on installing CentOS7 on VMware 15.5

1. Create a new virtual machine in VMware 15.5 1....

JavaScript function call, apply and bind method case study

Summarize 1. Similarities Both can change the int...

Summary of learning HTML tags and basic elements

1. Elements and tags in HTML <br />An eleme...

Vue uses canvas to realize image compression upload

This article shares the specific code of Vue usin...

How to check PCIe version and speed in Linux

PCIE has four different specifications. Let’s tak...