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

Do you know how to use the flash wmode attribute in web pages?

When doing web development, you may encounter the...

Realizing provincial and municipal linkage effects based on JavaScript

This article shares the specific code of JavaScri...

JavaScript to achieve accordion effect

This article shares the specific code for JavaScr...

Detailed explanation of CocosCreator optimization DrawCall

Table of contents Preface What is DrawCall How do...

Use of Linux gzip command

1. Command Introduction The gzip (GNU zip) comman...

Install multiple versions of PHP for Nginx on Linux

When we install and configure the server LNPM env...

Tutorial on using portainer to connect to remote docker

Portainer is a lightweight docker environment man...

Example of using MySQL to count the number of different values ​​in a column

Preface The requirement implemented in this artic...

Mysql Sql statement exercises (50 questions)

Table name and fields –1. Student List Student (s...

Introduction and examples of hidden fields in HTML

Basic syntax: <input type="hidden" na...

Detailed explanation of how to detect and prevent JavaScript infinite loops

Table of contents Preface Fix infinite loop in fo...