1:创建普通用户
create user user_name@'%' identified by 'password';
2:给用户授权
指定所有操作权限给用户
grant all privileges on testDB.* to 'user_name'@'localhost' identified by 'password'; //本地授权
grant all privileges on testDB.* to 'user_name'@'%' identified by 'password'; //远程授权
all 可以替换为 select,delete,update,create,drop
flush privileges; #刷新系统权限表
指定部分权限给用户
grant select,update on testDB.* to 'user_name'@'localhost' identified by 'password';
flush privileges; #刷新系统权限表
如上授权可能因为mysql的版本不同会有区别,如果报错,请使用以下授权语句
GRANT GRANT OPTION ON `db_test`.* TO 'user_name'@'%'; //指定访问的数据库
GRANT SELECT ON *.* TO 'user_name'@'%' IDENTIFIED BY 'password'; //指定可以访问所有的数据库
flush privileges; #刷新系统权限表
删除用户
Delete FROM mysql.user Where user='user1';