忘記Mysql密碼後重置mysql密碼

1、忘記了mysql密碼,可以先通過設置my.cnf文件爲任意登錄,一般是在/etc目錄下,可以用locate命令查找一下

[root@VM_184_46_centos etc]# locate my.cnf
/etc/my.cnf
/etc/my.cnf.d
[root@VM_184_46_centos etc]# 

2、使用 vim /etc/my.cnf命令編輯該文件(建議先備份),在[mysqld]下面加上 skip-grant-tables ,
這裏寫圖片描述

3、保存後執行service mysql restart 重啓mysql
這裏寫圖片描述
4、接下來就可以用命令登錄mysql了,登錄後修改mysql密碼

# mysql -uroot -p

mysql> use mysql; 
mysql> update user set password=password('123') where user='root'; 
mysql> flush privileges; 

5、Ctrl+C退出mysql

6、 vim /etc/my.cnf 刪除剛剛的 skip-grant-tables

7、重啓mysql,完成。

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