首先:去 mysql 库中查看 root 用户的权限
select * from user where user = 'root' and host='localhost';
查看root权限为所有ip都可以访问
mysql> show grants for root;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD
1、授权test用户拥有 mydatabase 数据库的所有权限(某个数据库的所有权限):
mysql>grant all privileges on mydatabase.* to user@localhost identified by '123456';
mysql>flush privileges;//刷新系统权限表
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
2、指定部分权限给一用户,可以这样来写:
mysql>grant select,update on testDB.* to test@localhost identified by '123456';
mysql>flush privileges; //刷新系统权限表
3、授权test用户拥有所有数据库的某些权限:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "123456";
//test用户对所有数据库都有select,delete,update,create,drop 权限。
//@"%" 表示对所有非本地主机授权,不包括localhost