1.添加新的用戶
允許本地 IP訪問localhost的Mysql數據庫
mysql> create user 'test'@'localhost' identified by 'test123456'; Query OK, 0 rows affected (0.06 sec)
允許所有的IP都可以訪問該數據庫
mysql> create user 'test'@'%' identified by 'test123456'; Query OK, 0 rows affected (0.00 sec)
用戶創建完成后,刷新授權
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec
刪除用戶
DROP USER test@localhost;
修改用戶密碼
update mysql.user set password=password("新密碼") where user="root";flush
privileges
;
2.權限分配
//首先為用戶創建一個數據庫(phplampDB)
mysql>create database phplampDB;
//授權phplamp用戶擁有phplamp數據庫的所有權限
mysql>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統權限表
mysql>flush privileges;
//如果想指定部分權限給一用戶,可以這樣來寫:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統權限表
mysql>flush privileges;
//權限格式
mysql> grant 權限1,權限2,…權限n on 數據庫名稱.表名稱 to 用戶名@用戶地址 identified by ‘連接口令’; 權限1,權限2,…權限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個權限。 當權限1,權限2,…權限n被all privileges或者all代替,表示賦予用戶全部權限。 當數據庫名稱.表名稱被*.*代替,表示賦予用戶操作服務器上所有數據庫所有表的權限。 用戶地址可以是localhost,也可以是ip地址、機器名字、域名。也可以用’%'表示從任何地址連接。 連接口令不能為空,否則創建失敗。
例如:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數據庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的權限,並設定口令為123。
mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對數據庫vtdc所有表進行所有操作的權限,並設定口令為123。
mysql>grant all privileges on *.* to joe@10.163.225.87 identified by ‘123′;
給來自10.163.225.87的用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令為123。
mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;
給本機用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令為123。