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

A brief discussion on the lazy loading attribute pattern in JavaScript

Table of contents 1. Introduction 2. On-demand at...

Native JS music player

This article example shares the specific code of ...

WebStorm cannot correctly identify the solution of Vue3 combined API

1 Problem Description Vue3's combined API can...

Overview of time configuration under Linux system

1. Time types are divided into: 1. Network time (...

Vue implements form data validation example code

Add rules to the el-form form: Define rules in da...

MySQL full-text fuzzy search MATCH AGAINST method example

MySQL 4.x and above provide full-text search supp...

Html tips to make your code semantic

Html semantics seems to be a commonplace issue. G...

Steps to build a Docker image using Dockerfile

Dockerfile is a text file that contains instructi...

Teach you to create custom hooks in react

1. What are custom hooks Logic reuse Simply put, ...

Detailed explanation of Tomcat's Server Options

1. Configuration By default, the first two are no...

Share 8 very useful CSS development tools

CSS3 Patterns Gallery This CSS3 pattern library s...

How to modify the root password of mysql in docker

The first step is to create a mysql container doc...

How to find out uncommitted transaction information in MySQL

A while ago, I wrote a blog post titled "Can...

jQuery achieves large-screen scrolling playback effect

This article shares the specific code of jQuery t...