一、修改用戶密碼
格式(在命令行下輸入):mysqladmin -u 用戶名 -p舊密碼 password 新密碼
1. 給root添加密碼ab12:? mysqladmin -uroot -password ab12
2. 將root的密碼修改為djg345:??? mysqladmin -uroot -pab12 password djg345
二、添加新用戶
格式:grant 權限 on 數據庫名.表名 to 用戶名@登錄主機? identified by "密碼"
1. 增加一個用戶test1密碼為abc,讓他可以在任何主機上登錄,并對所有數據庫有查詢、插入、修改、刪除的權限。首先用以root用戶連入MYSQL,然后鍵入以下命令:
grant select, insert, update, delete on *.* to test1@"%" identified by "abc";
2. 增加一個用戶test2密碼為abc,讓他只可以在localhost上登錄,并可以對數據庫mydb進行查詢、插 入、修改、刪除的操作(localhost指本地主機,即MYSQL數據庫所在的那臺主機),這樣用戶即使用知道test2的密碼,他也無法從 internet上直接訪問數據庫,只能通過MYSQL主機上的web頁來訪問了。
grant select, inset, update, delete on mydb.* to test2@localhost indetified by "abc";
如果你不想test2有密碼,可以再次輸入一個命令將密碼取消:
grant select, insert, update, delete on mydb.* to test2@localhost identified by "";