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
Release: 2020-03-11 10:46:36
Original
5412 people have browsed it

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
Copy after login
Copy after login

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
Copy after login

Then save and exit

2. Restart the mysql service

service mysqld restart
Copy after login

so that you can skip verification and enter mysql directly

3. Enter mysql

mysql
Copy after login

4. Execute the sql statements in sequence

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

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' ;
Copy after login

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

vim /etc/my.cnf
Copy after login
Copy after login

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

6. Restart the mysql service

service mysqld restart
Copy after login

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

mysql -uroot -p
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template