Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method and steps of MySQL authorizing remote connection in Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report