步驟:
1. 停止mysqld資料庫服務
shell> service mysql stop
注:如果有使用者擁有shutdown許可權,則可以使用mysqladmin --user=xxx -password shutdown停止mysqld服務

 

2. 以--skip-grant-tables選項啟動mysqld資料庫服務
shell> mysqld --datadir=/var/data/ --pid-file=/var/data/xxx.pid --skip-grant-tableswww.it165.net
注:datadir指定資料庫資料目錄,pid-file指定內容為mysqld進程號的檔,指定skip-grant-tables選項,mysqld啟動時忽略許可權驗證

 

3. 不使用密碼登錄mysql資料庫
shell> mysql -uroot mysql
注:不指定密碼選項(-p或--password),則使用空密碼登錄

 

4. 修改帳號root密碼
mysql> update user set password=password('root_pwd') where user='root';
mysql> flush privileges;
注:修改完密碼後,必須使用flush privileges語句讓密碼生效,這裡設置root帳號密碼為root_pwd

 

5. 停止mysqld資料庫服務
shell> mysqladmin --user=root -password shutdown
注:這次使用mysqladmin停止,linux下service不能停止手工啟動的mysql資料庫伺服器

 

6. 正常啟動mysql資料庫
shell> service mysql start


 

7. 使用新密碼登錄,發現密碼已經修改為新密碼
shell> mysql -uroot -proot_pwd mysql
 
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()