大家好,最近有用戶提出root口令忘記了怎么辦的需求,我也在網上看到過好多這樣的文章,寫的都挺好的,但有些還是有問題,不是少幾句話就是執行時出錯。我寫了一個簡單的小腳本,請大家多指教吧。很簡單但也很適用。
注意事項:
1。該腳本必須將屬主改為root,權限為700,否則有安全問題。
2。該腳本的作用是將root用戶的口令清除,若想改口令請用mysqladmin工具來做,或者進入后用update 命令也可
3。此腳本是針對系統自帶的mysql命令的。如果是自己安裝的源碼包,可以修改關于停止mysql的那一部分。
#!/bin/sh
#This is programme is recover the password of root for mysql databases.
#author is coffee_45
#data is 4月 4 12:14:03 CST 2005
#kill mysqld
/bin/kill `cat /var/run/mysqld/mysqld.pid` 2> /dev/null
#start mysqld with special paramaters
/usr/bin/safe_mysqld --skip-grant-tables &
sleep 3
#change password for root
chpw_mysql=/home/command_mysql
echo "use mysql" >$chpw_mysql 2> /dev/null
echo "update user set password=password('') where user='root';" >> $chpw_mysql 2>/dev/null
echo "quit" >> $chpw_mysql
mysql < $chpw_mysql
/etc/init.d/mysqld restart