1.创建用户
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER ‘用户名’@‘限制的IP地址’ IDENTIFIED BY ‘密码’;
2.授权
GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
#GRANT ALL ON *.* TO 'pig'@'%';
FLUSH PRIVILEGES; #不重启MySQL服务的情况下直接生效
#privileges:用户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使用ALL
#databasename:数据库名
#tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示,如.*
3.设置与更改用户密码
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
4.撤销用户权限
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
5.删除用户
DROP USER 'username'@'host';
6.限制ip
use mysql;
update user set host = '125.93.252.175' where user = 'root' and host = '%';
FLUSH PRIVILEGES;