一 用戶權限操作
增加新用戶,並給予指定的權限
格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼"
權限我常用兩種
1 select, insert, update, delete
2 ALL PRIVILEGES
數據庫
* 代表全部數據庫
notebase 指定數據庫
用戶名
root和非root用戶
登陸主機
localhost 本機訪問
% 所有IP都能訪問,這個比較危險
10.0.0.11 指定IP能訪問,常用的方法
我常用的方法
1 用於程序發佈中,指定數據庫,指定用戶,權限小不影響工作(程序和數據庫服務器在同一臺機器上,否則用指定IP或域名)
grant select, insert, update, delete on notebase.* to nb@localhost identified by 'nb123';
不推薦使用%,這樣所有的IP都能連接,不過只能對notebase操作
grant select, insert, update, delete on notebase.* to nb@"%" identified by 'nb123';
2 用於程序開發中,讓指定開發人員的機器有最高訪問權限
grant ALL PRIVILEGES on *.* to root@"10.0.0.11" Identified by "root" WITH GRANT OPTION;
二 mysql加密函數
順便提一下mysql用戶密碼問題
以下兩個語句都是改t用戶密碼,只是加密函數不一樣
1 mysql4.1以上的用法,我用上面加用戶權限時默認是這種加密函數
update user set password=password('test') where user='t';
flush privileges;
2 mysql4.1以下的用法,這種用法已經老了,只是一些舊程序中還在用
update user set password=old_password('test') where user='t';
flush privileges;
無論哪種都不影響我在mysql-5.0.22上正常登陸
但是程序中是否有影響,那就要具體問題具體分析了