Get the App
SLTechnology News&Howtos  ›  Database  › 

The method and steps of MySQL authorizing remote connection in Linux

Shulou Source: shulou.com Published: 2022-06-01 04:21:14 09月23日 Update

Note: when other IP cannot connect to the MySQL database without authorization through the client, if you need to remotely connect to the MySQL on the Linux system, you must authorize its IP and specific users. Generally speaking, root users will not provide it to developers. For example, if you use the SQLyog graphical management tool on Windows to connect to the MySQL database on Linux, you must first authorize it.

1. Log in to the mysql database using root users in the virtual machine

Mysql-u root-p

Description: root user password is generally set to root

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

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

Note: this command is authorized for any root user whose password is root or IP (%). (%: fuzzy query, all IP can be used, but the 'root' after IP;BY of other hosts can be specified as the password)

3. Write the configuration to the mysql authorization table

Mysql > flush privileges

Modify the user table of the mysql library to change the host entry from localhost to%. % here means that arbitrary host access is allowed. If only one ip access is allowed, it can be changed to the corresponding ip. For example, the localhost can be changed to 192.168.1.123, which means that only 192.168.1.123 ip of the local area network is allowed to access the mysql remotely.

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

Add: the firewall opens port 3306

1. Open the firewall configuration file

Vi / etc/sysconfig/iptables

2. Add the following line

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

3. Restart the firewall

Service iptables restart

Note: the addition of open port 3306 statements must precede icmp-host-prohibited

Attached: 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]-An INPUT-m state-- state ESTABLISHED RELATED-j ACCEPT-An INPUT-p icmp-j ACCEPT-An INPUT-I lo-j ACCEPT-An INPUT-I eth0-j ACCEPT-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 22-j ACCEPT-An INPUT-m state-- state NEW-m tcp-p tcp-dport 80-j ACCEPT-An 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-An INPUT-j REJECT-- reject-with icmp-host-prohibited-A FORWARD-j REJECT-- reject-with icmp-host-prohibitedCOMMIT

The above is the whole 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 and exchange, thank you for your support.

Tags: User password data database firewall configuration fire prevention content command port open one line personal host graphics customer that is local area local area network tools Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Linux MySQL Apple