1.创建用户:
命令:create user 'username'@'host' identified by 'password';
:flush privileges;
解释:username:用户名
:lost:主机名或ip
:password:密码
注:创建用户需要执行刷新命令,否则不能给新建用户授权。
例:(1)create user 'pnfy'@'192.168.1.100' identified by '123';
(2)create user 'pnfy'@'localhost' identified by '123';
(3)create user 'pnfy'@'127.0.0.1' identified by '123';
(4)create user 'pnfy'@'% identified by '123';
(5)create user 'pnfy'@'192.168.1.100';
2.授权:
命令:grant privileges on database.table to 'username'@'host' identified by 'password' with grant option;
:flush privileges;
解释:privileges:权限,all privileges,select,insert
:database:数据库名
:table:表名
:with grant option:该用户可将些权限授给其他用户
例:(1)grant all privileges on database.table to 'pnfy'@'%' identified by '123' with grant option;
(2)grant select,insert on zs.user to 'pnfy'@'%' identified by '123';