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
##1. First edit the /etc/my.cnf file
vim /etc/my.cnfAdd a line to configure skip-grant-tables in the fileFor example, add it to this location
# read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tablesThen save and exit
2. Restart the mysql service
service mysqld restartso 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.cnfRemove the skip-grant-tables configuration, save and exit
6. Restart the mysql service
service mysqld restartAt this point, you can log in with the new password!
mysql -uroot -pThis 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!