CentOS 6.x下重置MySQL 5.7密碼
阿新 • • 發佈:2019-02-09
本人環境為MySQL 5.7 + CentOS 6.3。
1. 編輯MySQL配置檔案/etc/my.cnf
找到[mysqld],在下面新增一行skip-grant-tables
2. 重啟MySQL
service mysqld restart
3. root使用者登入MySQL,提示密碼直接回車
mysql -uroot -p
4. 修改root密碼,並重新整理許可權
update mysql.user set authentication_string=password('新密碼') where user='root' and host='localhost'; flush privileges;
5. 退出MySQL,並編輯MySQL配置檔案/etc/my.cnf
6. 重啟MySQL
service mysqld restart
7. 使用新密碼登入,測試修改成果
注意:如果MySQL是5.5,則修改密碼的語句是update mysql.user set password=password('123456') where user='root' and host='localhost';