linux mysql remote connection

Recently, I installed Mysql on Linux, and then connected through Navicat under Windows environment, an error occurred: 1045 Access denied for user'root'@'XXX' (using password: YES), as follows:

Connection error

First of all, it is possible to log in to mysql normally in Linux, so it will not be caused by a wrong user password.

Next, I considered that it might be related to the firewall, so I checked whether the firewall under Linux has opened the corresponding port, and found that the firewall is closed at this time, so the influence of the firewall can be excluded.

Finally, it suddenly occurred to me that the root user of mysql cannot connect remotely by default, so I logged into mysql in Linux and found that this is the reason. The solution is as follows:

  • 1. Log in to mysql, command:, mysql -u root -pand then enter the password.

Login to mysql

  • 2. View the host field of the user table in the mysql library

Use mysql library: use mysql query information: select user,host from user

search result

In the host field, localhost means that only the local machine is allowed to access. To realize remote connection, you can change the host of the root user to %,% means that any host is allowed to access. If you need to set to allow only specific ip access, you should change to the corresponding ip .

  • 3. Modify the host field of the root user, command:update user set host="%" where user="root"
  • 4. To make this modification effective immediately, order:flush privileges

Modified result

Finally, if you connect remotely in Navicat under windows, no error will be reported.

connection succeeded

The above is the Linux-related knowledge shared by Liangxu Tutorial Network for all friends.

Guess you like

Origin blog.csdn.net/manongxianfeng/article/details/113090885