MySQL password is correct but cannot log on locally, ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)

Source: Internet
Author: User

MySQL password is correct but cannot log on locally

The error is as follows:

ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)

The test found that the user table in the MySQL library was missing a data entry with root pointing to host:localhost, and that there was only one root point to host: the hostname data item, so you can't log in to MySQL with the root account.
As a summary, the root account is missing the account information that accesses the localhost, resulting in the inability to log on locally.

Workaround:
First kill the MySQL process and then in the parameters to start MySQL to add the skip password problem mode, as follows:
Vim/etc/my.cnf
and add skip-grant-tables under [MySQL],
This is used to skip password problems, but this is not a complete solution.

In the local with the MySQL command to enter the direct return to MySQL, but only the test and INFORMATION_SCHEMA database, no MySQL database, using the use MySQL reported the following error:
mysql> use MySQL
ERROR 1044 (42000): Access denied for user "@ ' localhost ' to database ' MySQL '
This means that no user is specified and there is no access to the database MySQL.
Then log in with root, enter the correct password to report the following error:
[Email protected] ~]# mysql-uroot-p123456
ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)
If the password is correct, the MySQL database has disabled the root user's local login rights.
Using the root user through the host 127.0.0.1 login can normally enter mysql,127.0.0.1 and localhost for the MySQL database is different host,

# mysql-uroot-p123456-h 127.0.0.1
This reminds me of the user table under MySQL.
We want to go to MySQL to see the user table, a method can be through the above command, if not, you can start the database with the following command, the default password entered

Steps:

[Email protected] ~]# mysql-uroot-p12345-h 127.0.0.1
mysql> use MySQL
Database changed
Mysql> Select User,host,password from user where user= ' root ';
+------+-----------------------+-------------------------------------------+
| user | Host | password |
+------+-----------------------+-------------------------------------------+
| Root | % | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | Localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | :: 1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
+------+-----------------------+-------------------------------------------+
4 rows in Set (0.02 sec)

mysql> Update user set host= ' localhost ' where user= ' root ' and host= '% ';
Query OK, 1 row affected (0.01 sec)
Rows matched:1 changed:1 warnings:0

mysql> flush Privileges;
Query OK, 0 rows affected (0.03 sec)

Mysql> quit
Bye
OK, quit MySQL and restart MySQL to solve the problem.

Compare before and after:
[Email protected] ~]# mysql-uroot-p
mysql> use MySQL;
Database changed
Mysql> Select User,host,password from user where user= ' root ';
+------+-----------------------+-------------------------------------------+
| user | Host | password |
+------+-----------------------+-------------------------------------------+
| Root | localhost | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | Localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
| Root | :: 1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |
+------+-----------------------+-------------------------------------------+
4 rows in Set (0.00 sec)

Mysql>
Ok!

MySQL password is correct but cannot log on locally, ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' (using Password:yes)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.