This article mainly introduces how to configure mysql under Linux to allow remote connections. Generally, we cannot connect remotely after installing mysql.
1. First, we install mysql on the linux system. By default in this article, the linux system can be connected to the Internet or the CD iso has been mounted. We use the command apt-get install mysql-server to install it. , after the installation is completed, check whether mysql is started and execute the command ps -e |grep mysql.
2. Verify whether remote connections are allowed initially. Since the virtual machine IP this time is 192.168.2.120, we execute mysql -h 192.168.20.120 -P 3306 -u root -proot (Note: -proot, root refers to the password of the root account), you can get the result that the connection cannot be made.
If we do not use remote connection, we can connect, the command is:
mysql -u root -proot。
# #3. Next, we connect to the database and execute the command use mysql; to use the mysql database.
And check the user table information, the execution command is:
select Host,User from user。
#4. Through the above steps, we can get the value in the data table user. Next, we update the record in the table to allow remote access,
The execution command is:update user set Host='%' where User ='root' limit 1;
5. Execute the forced refresh command flush privileges;
After execution, close Database Connectivity.
## 6. Change my.cnf in the mysql installation directory document.
Generally, the default path is under /etc/mysql/. Find the line bind-address = 127.0.0.1. You can delete it, comment it or change 127.0.0.1 to 0.0.0.0 and modify it. Save when finished.
7. Restart mysql, the command is service mysql restart. Perform a remote login test and you can see that remote connections are allowed.#Notes
Make sure“update user set Host='%' where User ='root' limit 1”
The above is the detailed content of How does MySQL database allow remote connections?. For more information, please follow other related articles on the PHP Chinese website!