zoukankan      html  css  js  c++  java
  • MYSQL权限的管理

    1.授权命令

    grant all on *.* to root@'localhost' identified by '123';
    grant all privileges on *.* to root@'localhost' identified by '123';
    
    grant 				#授权命令
    all privileges 		        #权限(所有权限)
    on 			        #在...上
    *.* 				#所有库.所有表
    to 			        #给
    root@'localhost' 	        #用户名@'主机域'
    identified 			#设置密码
    by 				#是
    '123';				#'密码'
    

    2.所有权限

    #查看用户权限
    mysql> show grants for lhd@'10.0.0.0/255.255.255.0';
    
    #回收权限
    mysql> revoke drop on *.* from lhd@'10.0.0.0/255.255.255.0';
    
    #所有权限
    SELECT, INSERT, UPDATE, DELETE, CREATE, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DROP, GRANT
    

    3.作用对象

    #授权root@'localhost'对所有库所有表拥有所有权限,密码是123
    grant all on *.* to root@'localhost' identified by '123';		#所有库所有表授权
    
    #授权root@'localhost'对wordpress库下所有表拥有所有权限,密码是123
    grant all on wordpress.* to root@'localhost' identified by '123';		#单库授权
    
    #授权root@'localhost'对wordpress库下所有表拥有查看,插入,修改的权限,密码是123(最常用)
    grant select,insert,update on wordpress.* to root@'localhost' identified by '123';	#指定权限单库授权
    
    #授权root@'localhost'用户对mysql库下的user表拥有查看,插入,修改的权限,密码是123
    grant select,insert,update on mysql.user to root@'localhost' identified by '123';	#单表授权
    
    #在企业中,单列授权被称为脱敏
    grant select(user) on mysql.user.host to root@'localhost' identified by '123';		#单列授权
    

    4.在企业里权限设定

    #开发跟你要一个数据库用户
    1.你要操作什么库,有没有指定表?
    2.你要什么用户?
    3.你从哪台主机连过来?
    4.密码你有没有要求?
    5.这个用户你要用多久?
    6.走流程,发邮件?
    
    #一般情况给开发的权限
    grant select,update,insert on dev.* to dev@'172.16.1.50' identified by 'QiuDao@123';
    
    #开发:你把root用户给我呗?--走开
    

    5.权限设置实践

    1.准备数据库

    #创建wordpress数据库
    create database wordpress;
    #使用wordpress库
    use wordpress;
    #创建t1、t2表
    create table t1 (id int);
    create table t2 (id int);
    
    #创建blog库
    create database blog;
    #使用blog库
    use blog;
    #创建t1表
    create table tb1 (id int);
    

    2.授权

    #授权wordpress@'10.0.0.5%'对于所有库所有表有查看权限,密码是123
    1.grant select on *.* to wordpress@'10.0.0.5%' identified by '123';
    
    #授权wordpress@'10.0.0.5%'对于wordpress下所有表有插入,删除,修改权限,密码是123
    2.grant insert,delete,update on wordpress.* to wordpress@'10.0.0.5%' identified by '123';
    
    #授权wordpress@'10.0.0.5%'对于wordpress下t1表所有权限,密码123
    3.grant all on wordpress.t1 to wordpress@'10.0.0.5%' identified by '123';
    

    3.提问

    #有一个人,使用wordpress用户通过10.0.0.51登录数据库,请问
    1.对于t1表,有哪些操作权限?
    	所有权限
    2.对于t2表,有哪些操作权限?
    	增、删、改、查
    3.对于tb1表,有哪些操作权限?
    	查
    

    4.总结

    1.如果不在同一级别授权,权限是相加关系
    2.但是我们不推荐在多级别定义重复权限。
    3.最常用的权限设定方式是单库级别授权
    	即:grant select,update,insert on dev.* to dev@'172.16.1.50' identified by 'QiuDao@123';
    4.如果涉及到敏感信息,我们使用脱敏,即单列授权
    	grant select(user) on mysql.user.host to root@'localhost' identified by '123';
    5.查看用户权限
    	show grants for 用户名@'主机域';
    
  • 相关阅读:
    监控网速
    nginx与apache 对比 apache是同步多进程模型,一个连接对应一个进程;nginx是异步的,多个连接(万级别)可以对应一个进程
    shell 爬虫
    shell 读写远程数据库
    tmp
    交换分区 在dd命令执行期间 top 其消耗系统约14%的cpu,而mem占比约为0
    中间变量 加层 对解决问题的思路 逆序生成
    ALLOWED_HOSTS = ['*']
    搭建一个简单的Python的Web环境 监控服务器内存 线程 进程 网络
    小米加步枪
  • 原文地址:https://www.cnblogs.com/Applogize/p/13293237.html
Copyright © 2011-2022 走看看