The linux mysql database opens the external access Settings guide

  • 2020-05-14 05:07:42
  • OfStack

Set MySQL under Linux and allow external machine access to sudo vi /etc/ my.cnf
Specific directory is specific situation and decide, some people are installed under the personal directory, then find the corresponding directory can.
1. Modification of configuration files
1.#sudo vim /etc/mysql/my.conf
Find bind-address = 127.0.0.1
Comment out the sentence
2. Modification of Mysql database
1) [root@etc etc]# mysql -u root -p
Enter password:
2)grant all privileges on database.* to admin@192.168.1.1 identified by 'password'
Note:
(1) 192.168.1.1 is the IP address of the client that wants to connect to the Mysql database, not the IP address of the database server where the Mysql database is located, remember
(2) password is the password of Mysql database root users, which needs to be modified according to the actual situation

How do I access the MySQL database on the Linux system?
Recently, I installed MySQL database in Linux system, but Linux system is a virtual machine, and the real host is Win7. I tried to access MySQL database under Win7 using MySQL database tool. But problems arise in the process of connecting:
Host '192.168.0.101' is not allowed to connect to this MySQL server
Then I baidu 1 under this problem, found the following several solutions.

Method 1 :(modify the table)
Enter the mysql database under the Linux system, open the user table, find the record whose "host" field value is "localhost", and update the value "localhost" to "%".
The command is as follows:
#mysql -u root -p
Enter password:
mysql > use mysql;
mysql > update user set host='%' where user='root' and host='localhost';
mysql > select host,user from user;

Method 2 :(authorization)
Case 1
If you want myuser to connect to the MySQL database server from any host using mypassword. Use the following authorization command:
GRANT ALL PRIVILEGES ON *.* TO [email='myuser'@'%']%27myuser%27@%27%%27[/email] IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
Case 2
If you want to allow the user myuser to connect to the MySQL database server from the host IP 192.168.0.101 and use mypassword as the password. Use the following authorization command:
GRANT ALL PRIVILEGES ON *.* TO [email='myuser'@'192.168.0.101']%27myuser%27@%27192.168.0.101%27[/email] IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
The above two methods are found on the Internet. I solved the problem I encountered through example 1 in the second method and successfully connected the MySQL database server in the Linux system.

Related articles: