1024programmer Linux What to do if you forget the MySQL password in Linux-linux operation and maintenance

What to do if you forget the MySQL password in Linux-linux operation and maintenance

1. First edit the /etc/my.cnf file

vim /etc/my.cnf

Add a line to the file to configure skip-grant-tables

For example, add it to this location

# read_rnd_buffer_size = 2M
 datadir=/var/lib/mysql
 socket=/var/lib/mysql/mysql.sock
 skip-grant-tables

Then save and exit

2. Restart the mysql service

service mysqld restart

In this way, you can skip the verification and directly enter mysql

3. Enter mysql

mysql

4. Execute sql statements in sequence

>use mysql;  change database
 >UPDATE user SET PASSORD =password('The new password you want to set') WHERE USER='root'; reset password
 >flush privileges; Refresh the MySQL system privilege related tables to prevent denial of access after changes; or restart the MySQL server
 >quit;

Note:

If you reset the password and report an error (ERROR 1054 (42S22): Unknown column 'PASSORD' in 'field list&#39 😉

Use

>update mysql.user set authentication_string=password('The new password you want to set  ') where user='root' ;

5. Edit the /etc/my.cnf file again

vim /etc/my.cnf

Remove the skip-grant-tables configuration, save and exit

6. Restart the mysql service

service mysqld restart

At this point, you can log in with the new password!

mysql -uroot -p

This article comes from the PHP Chinese website, Linux system tutorial column, please continue to pay attention to this column for more related tutorials !

The above is the detailed content of what to do if the MySQL password is forgotten in Linux. For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-to-do-if-you-forget-the-mysql-password-in-linux-linux-operation-and-maintenance/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索