01. 授权问题

Posted 桃源仙居

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了01. 授权问题相关的知识,希望对你有一定的参考价值。

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 [email protected]192.168.0.%;  

       grant alter  on testdb.* to [email protected]192.168.0.%;  

       grant drop   on testdb.* to [email protected]192.168.0.%;  
     
       grant references on testdb.* to [email protected]192.168.0.%; 

       grant create temporary tables on testdb.* to [email protected]192.168.0.%;  

       grant index on testdb.* to [email protected]192.168.0.%;  

       grant create view on testdb.* to [email protected]192.168.0.%;  

       grant show   view on testdb.* to [email protected]192.168.0.%;

       grant create routine on testdb.* to [email protected]192.168.0.%; 

       grant alter  routine on testdb.* to [email protected]192.168.0.%; 

       grant execute        on testdb.* to [email protected]192.168.0.%;

       grant all privileges on testdb to [email protected]localhost 
   

 

以上是关于01. 授权问题的主要内容,如果未能解决你的问题,请参考以下文章

19 01 11 javascript ?????????????????????(???????????????) ??????????????????????????????(代码片段

OkHttpInterceptor 从 kotlin 拦截器导航到登录片段

[linux][c/c++]代码片段01

read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) { errno: -4077(代码片段

来自fabric的Twitter登录在片段中不起作用

Sphinx、reStructuredText 显示/隐藏代码片段