Linux 下修改MySQL密碼

1. 管理員登錄Linux

2. 配置文件中增加跳過權限

2.1 編輯配置文件:

vim /etc/my.cnf

2.2 在文件最後一行輸入:

skip-grant-tables

2.3 保存

:wq

2.4 重啓MySQL服務

systemctl restart mysqld

3. root賬戶登錄MySQL

mysql -uroot -p

提示輸入密碼,直接回車。

4. 修改密碼

4.1 指定操作數據庫

use mysql

4.2 更新密碼爲123456

MySQL 5.7 之前:

update user set password=password('123456') where user='root';

MySQL 5.7 之後:

update user set authentication_string=password('123456') where user='root';

4.3 刷新權限

flush privileges;

4.4 退出MySQL

exit;

5. 還原配置文件

5.1 編輯配置文件:

vim /etc/my.cnf

5.2 註釋之前的一行:

# skip-grant-tables

5.3 保存

:wq

5.4 重啓MySQL服務

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