Linux中mysql 忘記root密碼的解決方法

一、編輯文件

vi /etc/my.cnf   

#編輯文件,找到[mysqld],在下面添加一行skip-grant-tablesmysql

[mysqld]sql

skip-grant-tableside

:wq!  #保存退出spa

#重啓MySQL服務rest

service mysqld restart  

二、進入MySQL控制檯

#直接按回車,這時不須要輸入root密碼。code

mysql -uroot -p  

三、修改root密碼

update mysql.user set password=password('123456') where User="root" and Host="localhost";ip

flush privileges;  #刷新系統受權表it

grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;io

四、取消/etc/my.cnf中的skip-grant-tables

vi /etc/my.cnf   編輯文件,找到[mysqld],刪除skip-grant-tables這一行table

:wq!  #保存退出

五、重啓mysql

service mysqld restart    #重啓mysql,這個時候mysql的root密碼已經修改成123456

六、進入mysql控制檯

mysql -uroot -p  #進入mysql控制檯

123456 #輸入密碼

相關文章
相關標籤/搜索