CentOS中對MySql的root用戶重置密碼


使用修改啟動服務參數的方式來更新user表,達到無密碼登陸的目的。

1.關閉系統下運行的mysql服務

(1)殺掉進程號達到關閉目的

先使用ps -ef|grep mysql查找進程號,然后使用kill+ PID的方式殺掉進程。

(2)使用systemctl工具來關閉mysql服務

systemctl stop mysql

 

2.修改mysql的啟動選項更新user表,達到無密碼登陸的效果

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables";

 

3.重新啟動mysql

systemctl start mysql

 

4.無密碼登錄mysql數據庫

mysql -u root

 

5.修改密碼

首先使用 flush privileges刷新權限表

然后使用alter user語句修改用戶登錄位置以及密碼

alter user 'root'@'localhost' identified by 'password'

5.6版本的mysql語句修改為

update mysql.user set password=password(‘**********’) where host='localhost' and user='root';

 

5.7(authentication_string)

再次刷新權限表

 

6.再次關閉mysql服務

7.恢復mysql啟動選項

systemctl unset-enviroment MYSQL_OPTS

8.開啟mysql服務

9.使用mysql -u root -p登錄mysql

 

 

 

新mysql設置密碼

 格式:mysql> set password for 用戶名@localhost = password('新密碼');  

 格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼

 

mysql> use mysql;  

mysql> update user set password=password('123') where user='root' and host='localhost';  

mysql> flush privileges;

 

mysql>grant all on *.* to 'root'@'localhost' IDENTIFIED BY '你的密碼'with grant option ;mysql>flush privileges;


免責聲明!

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



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