mysql之grant权限说明
mysql中给一个用户授权如select,insert,update,delete等其中的一个或者多个权限,主要使用grant命令,格式为:
给没有用户授权
grant 权限 on 数据库对象 to '用户'@'主机IP' identified by '密码';
给已经存在的用户授权
grant 权限 on 数据库对象 to '用户'@'主机IP';
一、grant普通用户,查询,插入,更新,删除数据库中的所有表的权利。
1、授予查看权限
mysql> grant select on mysql.user to 'ranran'@'localhost'; mysql> flushprivileges;
2、授予插入权限
mysql> grant insert on mysql.user to 'ranran'@'localhost'; mysql> flush privileges;
3、授予更新权限
mysql> grant update on mysql.user to 'ranran'@'localhost'; mysql> flush privileges;
4、授予删除权限
mysql> grant delete on mysql.user to 'ranran'@'localhost'; mysql> flush privileges;
5、查看授予的权限
mysql> show grants for 'ranran'@'localhost'; +----------------------------------------------------------------------------------------+ | Grants for ranran@localhost | +----------------------------------------------------------------------------------------+ | GRANT CREATE, CREATE USER ON *.* TO 'ranran'@'localhost' | | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `mysql`.`user` TO 'ranran'@'localhost' | +----------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
6、或者用一条命令插入
mysql> grant select,insert,update,delete on *.* to 'ranran'@'localhost';