Home >Operation and Maintenance >Linux Operation and Maintenance >What to do if you forget your MySQL password in Linux

What to do if you forget your MySQL password in Linux

angryTom
angryTomOriginal
2020-03-11 10:46:365384browse

What to do if you forget your MySQL password in Linux

What to do if you forget your MySQL password in Linux

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

vim /etc/my.cnf

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

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

so that you can skip verification and enter mysql directly

3. Enter mysql

mysql

4. Execute the sql statements in sequence

>use mysql;    更改数据库
>UPDATE user SET PASSORD =password('你要设定的新密码') WHERE USER= 'root';  重设密码
>flush privileges;  刷新MySQL的系统权限相关表,以防止更改后拒绝访问;或或者重启MySQL服务器
>quit;

Note:

If you reset the password, an error message will be reported (ERROR 1054 (42S22): Unknown column 'PASSORD' in 'field list')

Use

>update mysql.user set authentication_string=password('你要设定的新密码') 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 you forget your MySQL password in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn