(1)登录:
mysql -u root -p
(2)查看现有用户
select host,user,authentication_string from mysql.user;
(3)新建用户
create user "username"@"host" identified by "password";
/*host="localhost"为本地登录用户,host="ip"为ip地址登录,host="%",为外网ip登录*/
(4)删除用户
drop user 'username'@'host';
(5)授权
/*授予用户通过外网IP对于该数据库的全部权限*/
grant all privileges on `test`.* to 'test'@'%' ;
/*授予用户在本地服务器对该数据库的全部权限*/
grant all privileges on `test`.* to 'test'@'localhost';
grant select on test.* to 'user1'@'localhost'; /*给予查询权限*/
grant insert on test.* to 'user1'@'localhost'; /*添加插入权限*/
grant delete on test.* to 'user1'@'localhost'; /*添加删除权限*/
grant update on test.* to 'user1'@'localhost'; /*添加权限*/
flush privileges; /*刷新权限*/
(6)查看权限
show grants;
查看某个用户的权限:
show grants for 'jack'@'%';