Table of contents
foreword
MySQL database remote connection (local area network) refers to the process of connecting to the MySQL database server through the network between different computers or devices in the local area network. In this case, the MySQL database server is located on a computer in the local area network, and the clients that need to connect to the server can be other computers or devices in the same local area network.
client
If the client has mysql locally, it needs to be closed;
Windows, open the task manager, click on the service, find mysql to close;
Linux, close the local MySQL service in the system;
Turn on access
login mysql command
mysql -u root -p
Switch to the database named "mysql"
use mysql
Look at the data in the "user" and "host" columns of the "user" table
select user, host from user;
Enter the command to change the access rights of the root user. If the host value is changed to %, it means that the root user can log in to the mysql server on any client machine;
update user set host='%' where user='root';
To update the settings, run the command
flush privileges;
firewall settings
windows
Command: Used to permanently open TCP port 3306 in the firewall configuration. Here, port 3306 is the port that the MySQL database server listens to by default.
firewall-cmd --permanent --add-port=3306/tcp
Visualization: Open the firewall, advanced firewall settings, create a new rule for inbound rules, select the TCP port and fill in the port number 3306, select Allow all connections, and complete;
Linux
CentOS, Red Hat, the firewall management tool is firewalld, the following is the command for TCP port 3306:
sudo firewall-cmd --permanent --add-port=3306/tcp
sudo firewall-cmd --reload
Ubuntu, the firewall management tool is ufw, the following is the command for TCP port 3306:
sudo ufw allow 3306/tcp
sudo ufw reload
test connection
When changing the localhost in the MySQL database to the IP address to be connected;
It is actually switching the connection host of the database from the local host to the specified IP address, which enables the MySQL database to accept remote connections from the specified IP address.