Home > Database > Mysql Tutorial > body text

How does MySQL database allow remote connections?

黄舟
Release: 2017-08-03 11:00:19
Original
2605 people have browsed it

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.

How does MySQL database allow remote connections?

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。
Copy after login

How does MySQL database allow remote connections?

How does MySQL database allow remote connections?

# #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。
Copy after login

The execution result is shown in the figure below.

How does MySQL database allow remote connections?

#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;
Copy after login

(This command means to update the Host value of the first record whose User value is root in the user table and set it to %). After the update is completed, execute the previous query command for verification.

How does MySQL database allow remote connections?

5. Execute the forced refresh command flush privileges;

After execution, close Database Connectivity.

How does MySQL database allow remote connections?

## 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.

How does MySQL database allow remote connections?

7. Restart mysql, the command is service mysql restart. Perform a remote login test and you can see that remote connections are allowed.

How does MySQL database allow remote connections?

#Notes

Make sure

“update user set Host='%' where User ='root' limit 1”
Copy after login
This statement is executed successfully and the record is changed.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template