1.创建新用户的SQL语句:
CREATEUSER'pig'@'192.168.1.101_'IDENDIFIEDBY'123456';
// pig 是用户名,@后面的是指定ip(如果不限制只能在某个ip,@后面改为‘%’),by后面的是 密码
2.设置这个用户的权限,使用GRANT语句
(如限制某个用户只能查询,不能修改,或者限定只能查询特定的表)
语法:
mysql>grant权限1,权限2,...权限non数据库名称.表名称to用户名@用户地址identifiedby'连接口令';
可选的权限列表:select, insert, update, delete, create, drop,
index, alter, grant, references, reload,
shutdown, process, file等14个权限
eg:
1. mysql> grantselect,insert,update,delete,create,droponvtdc.employeetojoe@10.163.225.87identifiedby'123';
给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表
进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。
2. mysql>grantallprivilegesonvtdc.*tojoe@10.163.225.87identifiedby'123';
给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。
3. mysql>grantallprivilegeson*.*tojoe@10.163.225.87identifiedby'123';
给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
4. mysql>grantallprivilegeson*.*tojoe@localhostidentifiedby'123';
给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
5. mysql>flushprivileges;//刷新系统权限表