首页 > 其他 > 详细

01. 授权问题

时间:2016-12-28 19:46:29      阅读:199      评论:0      收藏:0      [点我收藏+]

0.如果mysql没有初始化密码,那么首先初始化密码

mysql –u root

mysql>update user set password=PASSWORD(123456) where user=root;

 

1.通过改表设置所有的IP可以登录

mysql -u root –p

mysql>use mysql;

mysql>update user set host = % where user = root;

mysql>select host, user from user;

使用root帐号和root的原始密码可以在任何主机登录

 

2.通过授权所有的IP可以登录

GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY 123456 WITH GRANT OPTION;

flush privileges;

 授权用户root使用密码123456从任意主机连接到mysql服务器

 

 

3.通过授权指定的IP可以登录

GRANT ALL PRIVILEGES ON *.* TO ‘root@218.12.50.60 IDENTIFIED BY mark WITH GRANT OPTION;

flush privileges;

授权用户root使用密码mark从指定ip为218.12.50.60的主机连接到mysql服务器:

 

4.权限限制

授权表达式:

grant 权限 on 数据库对象 to 用户 

数据对象为 *.*:对mysql服务器中所有的数据库和表进行授权

数据对象为dbname.*:对mysql服务器中单个数据库dbname下的所有表进行授权

数据对象为dbname.user:对mysql服务器中单个数据库dbname下的user表进行授权

解除授权表达式

revoke 权限 on 数据库对象 from 用户 

数据对象的界定与上面相同

mysql权限表达式

授权普通用户对数据库testdb的所有表CRUD的权限:

       grant select on testdb.* general_user@%  

       grant insert on testdb.* to general_user@%  

       grant update on testdb.* to general_user@% 
 
       grant delete on testdb.* to general_user@% 

       grant select(id,name,birth) on testdb.* general_user@% 

可以直接使用:

       grant select, insert, update, delete on testdb.* to general_user@%  


授权数据库开发人员权限:

       grant create on testdb.* to developer@192.168.0.%;  

       grant alter  on testdb.* to developer@192.168.0.%;  

       grant drop   on testdb.* to developer@192.168.0.%;  
     
       grant references on testdb.* to developer@192.168.0.%; 

       grant create temporary tables on testdb.* to developer@192.168.0.%;  

       grant index on testdb.* to developer@192.168.0.%;  

       grant create view on testdb.* to developer@192.168.0.%;  

       grant show   view on testdb.* to developer@192.168.0.%;

       grant create routine on testdb.* to developer@192.168.0.%; 

       grant alter  routine on testdb.* to developer@192.168.0.%; 

       grant execute        on testdb.* to developer@192.168.0.%;

       grant all privileges on testdb to dba@localhost 
   

 

01. 授权问题

原文:http://www.cnblogs.com/makexu/p/6228686.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!