Database------root account password is lost and retrieved

Lost root password recovery method

    1. close the mysql service
net stop mysql
    1. In administrator mode, enter the command
mysqld  --shared-memory --skip-grant-tables  --console

Note: This command will not end, do not close the window, open a new command window to continue

    1. Open the command prompt and directly use root to connect to the database (no password required)
mysql -uroot 
    1. Set the root account password in the mysql.user table to an empty string
update mysql.user set authentication_string = '' where user = 'root' ;
    1. Refresh permissions (this step is not necessary, and can also be solved by restarting the database)
flush privileges ;

    1. close 步骤 2open window
CTRL + C 强制中断服务,并关闭窗口 (也可以直接关闭窗口)
    1. Open the task manager CTRL + SHIFT + ESC, find mysqld in the process, if there is, end the process

This step is mainly to prevent the mysqld service not being closed in step 6

    1. Restart the MySQL service
net start mysql
    1. Link MySQL service
-- 在步骤4 中,已经将密码设置为 空
mysql -uroot 
    1. reset root password
alter user root@'%' identified by '新密码' ;
    1. Refresh permissions
-- 或者重启MySQL服务
flush privileges ;

Guess you like

Origin blog.csdn.net/weixin_52953038/article/details/126776283