解決linux下mysql初始密碼或者密碼忘記

1.   vim /etc/my.cnf

在[mysqld]加入

skip-grant-tables

然後保存退出

然後重啓mysql 

2 ./etc/init.d/mysqld restart

登錄

3  mysql -u root -p

4.  5.7版本前的mysql運行: update user set password=password("你的密碼") where user="用戶"; 

 4. 5.7版本後的mysql運行:update mysql.user set authentication_string=password('你的密碼') where user='用戶';  

5 exit; #退出 

6 編輯my.cnf文件刪掉skip-grant-tables 這一行,然後重啓MySQL,/etc/init.d/mysqld restart,否則MySQL仍能免密碼登錄

7 mysql -u root -p輸入密碼

 

 

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