linux - mysql - 忘記用戶名、密碼


1, 關閉mysql服務

/etc/rc.d/init.d/mysqld stop


2,使用 –skip-grant-tables選項啟動mysql服務

(1)打開文件 mysqld

vi /etc/rc.d/init.d/mysqld

(2)編輯文件 mysqld,在下面運行啟動的語句里增加--skip-grant-tables

/usr/bin/mysqld_safe --skip-grant-tables --datadir="$datadir" --socket="$socketfile"

--log-error="$errlogfile" --pid-file="$mypidfile"

加入--skip-grant-tables的意思是啟動mysql服務的時候跳 過權限表認證。啟動后,連接到mysql的root不需要口令

 

3,重新啟動mysql服務

/etc/rc.d/init.d/mysqld start

 

4,登錄mysql

 mysql -u root -h 127.0.0.1 -P3306 -p

備注:直接回車進入就好,此時不輸入密碼也可以登錄mysql

 

5,修改root用戶的密碼

mysql> select host,user,password from mysql.user;

mysql> update mysql.user set password=password('1111') where user='root';

mysql> flush privileges;

mysql> quit


5, 重新啟動mysql,就可以使用 新密碼登錄了

/etc/rc.d/init.d/mysqld restart   //重新啟動mysql

mysql -u root -h 127.0.0.1 -P3306 -p

輸入密碼:123456


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM