Reasons and solutions for Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES) when logging in to MySQL

Reasons and solutions for Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES) when logging in to MySQL. (Or use the mysql connection tool navicat to get the same error)

Enter image description

mysql -u root -h 192.168.194.142 -p

Enter password: ERROR 1045 (28000): Access denied for user 'root'@'192.168.194.142' (using password: YES)

【Solution】

  1. Login with localhost first

mysql -u root -p

Enter password: 2. Execute the authorization command mysql> grant all privileges on . to root@'%' identified by '123'; Query OK, 0 rows affected (0.07 sec) 3. Exit and try again mysql> quit Bye and try logging in again:

mysql -u root -h 192.168.194.142 -p

Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.33 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> Success!

The following describes in detail how to authorize users.

mysql> grant permission 1, permission 2, ... permission n on database name. table name to user name@user address identified by 'connection password';

Permission 1, Permission 2,... Permission n represents 14 permissions such as select, insert, update, delete, create, drop, index, alter, grant, references, reload, shutdown, process, and file. When privilege 1, privilege 2, ... privilege n is replaced by all privileges or all, it means that all privileges are given to the user. When the database name and table name are replaced by . , it means that the user has the authority to operate all tables in all databases on the server. The user address can be localhost, or it can be an IP address, machine name, and domain name. You can also use '%' to connect from any address. 'Connection password' cannot be empty, otherwise the creation will fail.

To give a few examples: mysql> grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by '123'; assign user joe from 10.163.225.87 an employee that can be used for database vtdc The table is authorized to perform operations such as select, insert, update, delete, create, drop, etc., and set the password to 123.

mysql> grant all privileges on vtdc.* to [email protected] identified by '123'; Assign the user joe from 10.163.225.87 the authority to perform all operations on all tables in the database vtdc, and set the password to 123.

mysql> grant all privileges on . to [email protected] identified by '123'; to assign the user joe from 10.163.225.87 the authority to perform all operations on all tables in all databases, and set the password to 123.

mysql> grant all privileges on . to joe @localhost identified by '123'; Assign the local user joe the authority to perform all operations on all tables in all databases, and set the password to 123.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325517859&siteId=291194637