How to remotely connect to the MySQL database in Linux, linuxmysql
Preface
I recently encountered this requirement in my work. It is estimated that the remote connection was completed after more than an hour. A local computer and an ECS are all linux systems. Next let's take a look at the detailed introduction:
Procedure
1. enable remote access on the server
First, enter the mysql database, and then enter the following two commands:
grant all privileges on *.* to 'root'@'%' identified by 'password';flush privileges;
The first is the database, which can be changed to the name of the database that is allowed to access.
The second is the database table name, which indicates that any table can be accessed.
Root indicates the user name used for remote logon. You can customize the user name.
% Indicates that any ip address is allowed to log on. If you want to specify a specific IP address, you can replace %.
Password indicates the password used for remote logon. It can be customized.
Flush privileges; this allows the permission to take effect immediately
2. Modify the my. cnf configuration file.
This is the mysql configuration file. If you cannot find any location in the Untitled article, enterfind /* -name my.cnf
Find
Use vim to edit the file and findbind-address = 127.0.0.1
In the preceding example, add a # sign to comment out and save and exit.
3. Restart the service
service mysql restart
4. Local remote connection
Enter at the terminal:
Mysql-h Server IP address-P 3306-u root-p
Enter the password.
Root is the username set at, and the password is also set
Some details
I found a lot of articles on the internet, saying that I had to enable port 3306 to connect, but I still couldn't connect to it. Later I found some articles, saying I had to change my. cnf, that is, point 2nd above, changed and then restarted the server.
I have just interviewed another server, but I have not configured any ports. The above three steps will soon be connected.
So the second point is very important. Basically, everyone configures the file when installing mysql, because the character set needs to be configured. So there must be that file. Use the find command to find it.
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.