方法一:用set password命令html
首先,登錄mysqlmysql
1
|
mysql -u root -p
|
而後執行set password命令sql
1
|
set
password
for
root@localhost =
password
(
'654321'
);
|
上面例子,將root密碼更改成654321ui
方法二:使用mysqladminspa
格式爲:mysqladmin -u用戶名 -p舊密碼 password 新密碼rest
1
|
mysqladmin -uroot -p123456
password
"654321"
|
上面例子,將root密碼由123456更改成654321code
方法三:更改mysql的user表htm
首先,登錄mysqlip
1
|
mysql -uroot -p
|
而後操做mysql庫的user表,進行updateci
1
2
3
|
mysql> use mysql;
mysql>
update
user
set
password
=
password
(
'654321'
)
where
user
=
'root'
and
host=
'localhost'
;
mysql> flush
privileges
;
|
方法四:忘記密碼的狀況下
首先中止mysql服務
1
|
service mysqld stop
|
以跳過受權的方式啓動mysql
1
|
mysqld_safe
--skip-grant-tables &
|
以root用戶登陸mysql
1
|
mysql -u root
|
操做mysql庫的user表,進行update
1
2
3
4
|
mysql> use mysql;
mysql>
update
user
set
password
=
password
(
'654321'
)
where
user
=
'root'
and
host=
'localhost'
;
mysql> flush
privileges
;
mysql> quit
|
重啓mysql服務
1
|
service mysqld restart
|