MySQL password is correct but cannot log in locally -1045

MySQL password is correct but cannot log in locally -1045

MySQL password is correct but cannot log in locally -1045 Access denied for user 'root'@'localhost' (using password:YES

MySQL password is correct but cannot log in locally

The error is as follows:

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

Solution:

1. Add the option to skip the password question in the parameters for starting MySQL, as follows:

vim /etc/my.cnf

And add skip-grant-tables under [mysql],

This is used to skip the password question, but it is not a complete solution.

2. Restart the MySQL service

I use Mysql in Linux system, the statement is as follows:

Check the port number:

ps aux|grep mysqld

Check the status:

systemctl status mysqld

Restart mysql service

systemctl restart mysqld

Try to connect:

mysql -uroot -p123456

Enter the password. You have just set it to skip the password, so you can ignore it.

The steps are as follows:

[root@localhost ~]# mysql -uroot -p123456
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, exit mysql, restart mysql to solve the problem

Compare before and after:

[root@localhost ~]# 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!

Summarize

The above is what I introduced to you. The MySQL password is correct but you cannot log in locally - 1045 Access denied for user ''root''@''localhost'' (using password: YES. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. Thank you very much for your support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • PHP+MySQL implements login verification to see if the login name and password are correct
  • Solution to the problem of being unable to log in locally even though the MySQL password is correct
  • How to correctly modify the ROOT password in MySql8.0 and above versions

<<:  Keepalived implements Nginx load balancing and high availability sample code

>>:  js method to realize shopping cart calculation

Recommend

JavaScript implements password box input verification

Sometimes it is necessary to perform simple verif...

React non-parent-child component parameter passing example code

React is a JAVASCRIPT library for building user i...

Implementation of breakpoint resume in vue-video-player

In a recent project, I needed to implement the fu...

Detailed explanation of the sticky position attribute in CSS

When developing mobile apps, you often encounter ...

Example of using Vue built-in component keep-alive

Table of contents 1. Usage of keep-alive Example ...

Mysql index types and basic usage examples

Table of contents index - General index - Unique ...

Pure js to achieve typewriter effect

This article example shares the specific code of ...

Vue gets token to implement token login sample code

The idea of ​​using token for login verification ...

Detailed explanation of how to upgrade software package versions under Linux

In the Linux environment, you want to check wheth...

Vue dynamic menu, dynamic route loading and refresh pitfalls

Table of contents need: Ideas: lesson: Share the ...

Vue state management: using Pinia instead of Vuex

Table of contents 1. What is Pinia? 2. Pinia is e...

Use of js optional chaining operator

Preface The optional chaining operator (?.) allow...

Introduction to the use of common Dockerfile commands

Table of contents 01 CMD 02 ENTRYPOINT 03 WORKDIR...