#授权表
user #该表放行的权限,针对:所有数据,所有库下所有表,以及表下的所有字段
db #该表放行的权限,针对:某一数据库,该数据库下的所有表,以及表下的所有字段
tables_priv #该表放行的权限。针对:某一张表,以及该表下的所有字段
columns_priv #该表放行的权限,针对:某一个字段
#按图解释:
user:放行db1,db2及其包含的所有
db:放行db1,及其db1包含的所有
tables_priv:放行db1.table1,及其该表包含的所有
columns_prive:放行db1.table1.column1,只放行该字段
查看MYSQL数据库中所有用户及拥有权限
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
开通mysql root 用户远程访问权限
/*基于安全考虑root账户一般只能本地访问,但是在开发过程中可能需要打开root的远程访问权限。下面是基本的步骤:
1、登录到mysql中,为root进行远程访问的授权,执行下面的命令:*/
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
mysql> flush privileges;
/*
第一句中"%"表示任何主机都可以远程登录到该服务器上访问。如果要限制只有某台机器可以访问,将其换成相应的IP即可,如:
GRANT ALL PRIVILEGES ON *.* TO root@"127.0.1.1" IDENTIFIED BY "root";
第二句表示从mysql数据库的grant表中重新加载权限数据。因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。
*/
举例
#创建用户create user 'egon'@'1.1.1.1' identified by '123';create user 'egon'@'192.168.1.%' identified by '123';create user 'egon'@'%' identified by '123';
#授权:对文件夹,对文件,对文件某一字段的权限
查看帮助:helpgrant常用权限有:select,update,alter,deleteall可以代表除了grant之外的所有权限
#针对所有库的授权:*.*
grant select on *.* to 'egon1'@'localhost' identified by '123'; #只在user表中可以查到egon1用户的select权限被设置为Y
#针对某一数据库:db1.*
grant select on db1.* to 'egon2'@'%' identified by '123'; #只在db表中可以查到egon2用户的select权限被设置为Y
#针对某一个表:db1.t1grant select on db1.t1 to 'egon3'@'%' identified by '123'; #只在tables_priv表中可以查到egon3用户的select权限
#针对某一个字段:grant select (id,name),update (age) on db1.t3 to 'egon4'@'localhost' identified by '123';
#可以在tables_priv和columns_priv中看到相应的权限
#删除权限revoke select on db1.* from 'egon'@'%';
实例:
create user 'egon1'@'%' identified by '123';
grant select on *.* to egon1;
select * from user where user='egon1';
grant select on db1.* to egon1;
select * from db where user='egon1';
grant all on db1.t1 to egon1;
select * from tables_priv where user='egon1';
grant select (name) , update(age) on db1.t1 to egon1;
select * from columns_priv where user='egon1';