What to do if Navicat (or other database viewing software) cannot connect to mysql?

Generally, there are several situations that cannot connect to mysql:

1. Wrong password;

2. Mysql is not set to allow other ip to connect;

What is discussed here is that there are both cases in mysql under linux. And our solution is relatively simple, the first step is to modify the configuration; the second step is to modify the password; the third step is to configure permissions so that all ip can be connected; the fourth step is to refresh and save the configuration to take effect; finally, verify one time. Isn't it very simple. Let's get started:

1. Modify the configuration file my.cnf, so where is this file, enter the following sentence in the server command line to open the my.cnf file:

vi /etc/my.cnf

2. After opening, add skip-grant-tables under the configuration file [mysqld]. How do you enter this sentence? Simple: Press the Insert key on the keyboard, and then the cursor will blink, indicating that you can enter. After typing, feel free to shift+: two keys at the same time, and then enter !wq to exit.

[mysqld]

skip-grant-tables

3. Then you can use the root user with an empty password to connect to MySQL and change the root password. Enter the following sentence (the following sentence does not need to use a password):

mysql -u root

4. Then enter the following state:

mysql> 

5. Enter after mysql:use mysql;

Then enter: update user set password=password('123456') where User='root';

Enter these two sentences to change the password of the root user to 123456.

mysql> use mysql;
Database changed
mysql> update user set password=password('123456') where User='root';
Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

Note: In general, the above two sentences can be solved, but (it seems to be a problem with the later version of mysql, the version of the password field is gone, and it is changed to authentication_string). So, use this sentence:

update user set authentication_string=password('123456') where user='root';

6. OK, remember to refresh it after the modification to make it take effect. enter:flush privileges;

mysql> update user set password=password('123456') where User='root';

ERROR 1046 (3D000): No database selected

mysql> use mysql;

Database changed

mysql> update user set password=password('123456') where User='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;

7. Finally enter:exit退出

mysql> update user set password=password('123456') where User='root';

ERROR 1046 (3D000): No database selected

mysql> use mysql;

Database changed

mysql> update user set password=password('123456') where User='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> exit

8. Remember to come back and delete the sentence just configured in my.cnf, which is the above steps 1 and 2, delete the skip-grant-tables in step 2 , and then save it.

9. The exciting time has come. You can now log in with the new password. Hurry up and verify it with navicat. If you are connecting remotely, remember to change the host ip address below to the ip of your linux server.

10. The previous modification has been done, but we want all devices to be able to remote database

1. Log in to the host as the root account on Linux

2. Log in to MySQL on the host

mysql -uroot -p123456

3. Delete the original  root@% user first (skip this step if it has not been created before)

drop user 'root'@'%';

Fourth, the deletion is successful, and then create a user root@%

create user 'root'@'%' identified with mysql_native_password by '123456';

5. Then authorize

grant all on *.* to 'root'@'%' with grant option;

6. Refresh configuration

flush privileges;

7. Exit

exit;

Guess you like

Origin blog.csdn.net/anything14/article/details/127856256
Recommended