作者: falcon 發表日期: 2006-06-13 19:54
復制鏈接
下面的這個來自:
http://www.yesky.com/searchdatabase/504969419638702080/20050224/1914572.shtml
在MySQL中修改一個用戶(比如叫"hunte")的密碼,可以用如下3個辦法:
#在控制臺上輸入 bash$ mysql -u root mysql #用mysql客戶程序 mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='hunte'; mysql> FLUSH PRIVILEGES; mysql> QUIT
#在控制臺上輸入 bash$ mysql -u root mysql #用mysql客戶程序 mysql> SET PASSWORD FOR hunte=PASSWORD('new password'); mysql> QUIT
#直接在控制臺上輸入 bash$ mysqladmin -u root "old password" "new password"
|
|
1)其實,上面的所有命令操作的對象都是mysql.user(mysql數據庫的user表),而第一種操作方法剛好放映了這個,不相信。你查看一下mysql.user的內容。
2)另外,我們可以在分配權限給用戶的時候,直接指定該用戶的密碼,具體操作可以是這個樣子
falcon@falcon:~$ sudo -s Password: root@falcon:~# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 to server version: 5.0.21-Debian_3ubuntu1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all on *.* to 54falcon identified by '54falcon'; Query OK, 0 rows affected (0.51 sec)
mysql> quit Bye root@falcon:~# mysql -u 54falcon -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 to server version: 5.0.21-Debian_3ubuntu1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> select user,password from mysql.user where user='54falcon'; +----------+------------------+ | user | password | +----------+------------------+ | 54falcon | 3e4722567adf268d | +----------+------------------+ 1 row in set (0.01 sec)
|
|
看到沒有阿,密碼已經指定阿,而且54falcon用戶的權限也是不小的,呵呵。
3)誒,上面我們提到,既然用戶和密碼信息存放在mysql.user里頭,我們是不是可以直接通過操作mysql.user來進行用戶和密碼的管理呢?回答是肯定的拉,呵呵
看看
mysql> insert into mysql.user(user) values('5454falcon'); Query OK, 1 row affected (0.02 sec)
mysql> select user from mysql.user where user like '%falcon%'; +------------+ | user | +------------+ | 5454falcon | | 54falcon | | falcon | +------------+ 3 rows in set (0.04 sec)
|
|
看到沒,最上面的那個用戶就是我們剛才插入的哦,要是想給個密碼,用最開始給出方法就可以搞定拉。
誒,到此結束拉。