博客來網路書店查詢

書名

博客來網路書店查詢

星期三, 1月 30, 2008

如果忘記mysql的root密碼(Linux)?

1.請先刪除所有執行中的mysql程序:
# killall mysqld
2.請檢查系統裡是否仍有mysql程序在執行:
# ps -aux |grep 'mysql'
3.請找尋mysqld_safe這一個檔案 (不同的Linux會有不同的位置)
# find / -name 'mysqld_safe'
/usr/bin/mysqld_safe
4.執行mysqld_safe
# /usr/bin/mysqld_safe --skip-grant-tables&
[1] 17591
# Starting mysqld daemon with databases from /var/lib/mysql
5.您可以再次檢查系統裡是否仍有mysql程序在執行:
# ps -aux |grep 'mysql*'
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root 17591 0.0 0.0 65848 1196 pts/1 S 17:18 0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 17631 0.5 1.1 189024 23656 pts/1 Sl 17:18 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock --skip-grant-tables
root 17643 0.0 0.0 61088 652 pts/1 S+ 17:18 0:00 grep mysql*
6.直接輸入mysql就可以進入
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

7.請輸入
use mysql;
代表使用mysql這一個資料庫
8.更新root的密碼
update user set password=password("新密碼") where user="root";
9.如需加入新的使用者,也可在這時加入
grant all privileges on *.* to username@localhost identified by 'userpassword';
10.更新改變
flush privileges;
11.離開 exit
12.請檢查系統裡mysql程序的pid:
# ps -aux |grep 'mysql*'
再使用kill pid的方式刪除。
13.啟動mysql程序
/etc/rc.d/init.d/mysqld start

沒有留言: