
在安裝mysql的時候如果沒有設置新的密碼,默認值為空或者12456,這樣安裝是沒有問題的也可以使用命令行mysql -uroot -p進行登錄。但是在正式使用的時候你不想密碼為空,或者為123456這樣簡單,以下是強制修改mysql的root密碼的四種方法: 第一種方法:使用upd
在安裝mysql的時候如果沒有設置新的密碼,默認值為空或者12456,這樣安裝是沒有問題的也可以使用命令行mysql -uroot -p進行登錄。但是在正式使用的時候你不想密碼為空,或者為123456這樣簡單,以下是強制修改mysql的root密碼的四種方法:
第一種方法:使用update語句進行修改
[root@localhost ~]# mysql -uroot -p
mysql->user mysql;
mysql> update user set Password=password('newpassword') where User='root' and Host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>quit
重新登錄即可
第二種方法:使用mysql自身提供的工具進行修改(mysqladmin)
[root@localhost ~]# mysqladmin -u root -poldpassword password 'newpassword';
第三種方法:使用set語句進行修改
[root@localhost ~]# mysql -uroot -p
mysql->user mysql;
mysql>set password for root@"localhost" = password("newpassword");
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>quit
重新登錄即可
第四種方法:使用grant語句進行修改
[root@localhost ~]# mysql -uroot -p
mysql>user mysql;
mysql>grant all privileges on *.* to root@'localhost' identified by 'newpassword';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>quit
重新登錄即可
第五種方法:使用phpmyadmin就行修改
以上方法本人親自測試過,每種方法都可以強制修改mysql的root用戶的密碼。
原文地址:5種強制修改mysql的root密碼的方法, 感謝原作者分享。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com