一、 在已知MYSQL數據庫的ROOT用戶密碼的情況下,修改密碼的方法:
1、 在SHELL環境下,使用mysqladmin命令設置:mysqladmin –u root –p password “新密碼” 回車後要求輸入舊密碼
2、 在mysql>環境中,使用update命令,直接更新mysql庫user表的數據:
Update mysql.user set password=password(‘新密碼’) where user=’root’;
flush privileges;
注意:mysql語句要以分號”;”結束
3、 在mysql>環境中,使用grant命令,修改root用戶的授權權限。
grant all on *.* to root@’localhost’ identified by ‘新密碼’;
二、 如查忘記了mysql數據庫的ROOT用戶的密碼,又如何做呢?方法如下:
1、 關閉當前運行的mysqld服務程序:service mysqld stop(要先將mysqld添加爲系統服務)
2、 使用mysqld_saft腳本以安全模式(不加載授權表)啓動mysqld 服務
/usr/local/mysql/bin/mysqld_saft --skip-grant-table &
3、 使用空密碼的root用戶登錄數據庫,重新設置ROOT用戶的密碼
#mysql -u root
Mysql> Update mysql.user set password=password(‘新密碼’) where user=’root’;
Mysql> flush privileges;