CentOS 6.x下重置MySQL 5.7密碼

本人環境爲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';

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章