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

Example of pre-rendering method for Vue single page application

Table of contents Preface vue-cli 2.0 version vue...

Vue Getting Started with Weather Forecast

This article example shares the specific code of ...

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...

How to prevent duplicate submission in jquery project

In new projects, axios can prevent duplicate subm...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

Example of how to quickly build a LEMP environment with Docker

LEMP (Linux + Nginx + MySQL + PHP) is basically a...

Solve the abnormal error when building vue environment with webpack

Table of contents First, configure package.json T...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

XHTML introductory tutorial: Application of table tags

<br />Table is an awkward tag in XHTML, so y...

Examples of clearfix and clear

This article mainly explains how to use clearfix a...

How to check the version of Kali Linux system

1. Check the kali linux system version Command: c...

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface Since vue3.0 was officially launched, man...