What to do if you forget your mysql password

What to do if you forget your mysql password

Solution to forgetting MySQL password:

[root@localhost ~]# mysql -uroot -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

If this happens, it's usually because MySQL is not up.

[root@localhost ~]# mysql -uroot -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

When this happens, it is usually because the password is entered incorrectly.

Solution:

1. Stop MySQL

[root@localhost ~]# service mysqld stop
Stopping mysqld: [ OK ]

2. Modify the configuration file and add the following content to the last line

skip-grant-tables //Skip authorization and enter the database directly

3. Restart MySQL

[root@localhost ~]# service mysqld start
[root@localhost ~]# mysql -uroot -p  
mysql>

4. Reset the password for MySQL

mysql> use mysql //The password is stored in MySQL, you need to enter mysql> desc user; //View the fields in the user table. Passwords are generally stored in the password table. +------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |

mysql> update user set password=password('passw0rd') where user="root"; //Set the password to passw0rd
mysql> flush privileges; // refresh

5. Then log out and log in again

[root@localhost ~]# mysql -uroot -ppassw0rd
mysql>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to recover MySQL password if you forget it
  • How to modify mysql user password and how to solve mysql password forgetting
  • Six ways to force change the mysql root password (mysql password forgotten)
  • Multiple solutions for linux mysql forgotten password or Access denied for user ''root''@''localhost''
  • MySql login password forgotten and password forgotten solution
  • How to solve the mysql password forgetting (linux and windows summary)
  • Solution to forgetting mysql password
  • Solution for forgetting the password of MySQL root user in Windows
  • How to modify the mysql database password when you forget it
  • Solution to forgetting mysql password under linux

<<:  Sample code for deploying Spring-boot project with Docker

>>:  Introduction to the common API usage of Vue3

Recommend

XHTML no longer uses some obsolete elements in HTML

When we do CSS web page layout, we all know that i...

Why should you be careful with Nginx's add_header directive?

Preface As we all know, the nginx configuration f...

Native js to realize bouncing ball

On a whim, I wrote a case study of a small ball b...

CSS border half or partially visible implementation code

1. Use pseudo-classes to display half of the Bord...

How to use Nginx proxy to surf the Internet

I usually use nginx as a reverse proxy for tomcat...

If I change a property randomly in Vue data, will the view be updated?

Interviewer: Have you read the source code of Vue...

Reasons why MySQL cancelled Query Cache

MySQL previously had a query cache, Query Cache. ...

Nginx uses reverse proxy to implement load balancing process analysis

Introduction Based on docker container and docker...

Specific use of node.js global variables

Global Object All modules can be called global: r...

Detailed explanation of the role of explain in MySQL

1. MYSQL index Index: A data structure that helps...

Example of making a butterfly flapping its wings with pure CSS3

Pure CSS3 makes a butterfly flapping its wings, s...

CSS3 to achieve menu hover effect

Result: html <nav id="nav-1"> <...