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

Detailed analysis of MySQL 8.0 memory consumption

Table of contents 1. innodb_buffer_pool_size 2. i...

How to install Composer in Linux

1. Download the installation script - composer-se...

Linux Check the installation location of the software simple method

1. Check the software installation path: There is...

About the problems of congruence and inequality, equality and inequality in JS

Table of contents Congruent and Incongruent congr...

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

Implementation of importing and exporting docker images

Docker usage of gitlab gitlab docker Startup Comm...

Basic JSON Operation Guide in MySQL 5.7

Preface Because of project needs, the storage fie...

CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

The default scroll bar style in Windows is ugly, ...

Summary of some common techniques in front-end development

1. How to display the date on the right in the art...

Solve the problem of insufficient docker disk space

After the server where Docker is located has been...

Detailed explanation of fetch network request encapsulation example

export default ({ url, method = 'GET', da...