一、创建用户的语法:create user 'username'@'host' identified by 'password';
username:你将创建的用户名
host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机 登陆,可以使用通配符%
password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
举例:
1.创建一个pig用户,并指定登录密码:123456,可以在任何一台远程主机都可以登录
create user 'pig'@'%' identified by '123456';
2.创建一个pig用户,并指定登录密码:为空,指定在120网段的机器登录
create user 'pig'@'120.%.%.%' identified by '';
2.1查看权限:
select * from mysql.user where user='pig'\G
mysql> show grants for 'pig'@'%';
+---------------------------------+
| Grants for pig@% |
+---------------------------------+
| GRANT USAGE ON *.* TO 'pig'@'%' |
+---------------------------------+
USAGE:无权限的意思
mysql> show grants for 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
WITH GRANT OPTION:表示这个用户拥有grant权限,即可以对其他用户授权
二、删除用户语法:drop user 'username'@'host';
drop user 'pig'@'%';
delete from mysql.user where user='pig';