当前位置: 首页 > news >正文

【mysql】mysql 用户管理---创建、权限管理等等

  本站以分享各种运维经验和运维所需要的技能为主

《python零基础入门》:python零基础入门学习

《python运维脚本》: python运维脚本实践

《shell》:shell学习

《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战

《k8》从问题中去学习k8s

《docker学习》暂未更新

《ceph学习》ceph日常问题解决分享

《日志收集》ELK+各种中间件

《运维日常》运维日常

《linux》运维面试100问

《DBA》db的介绍使用(mysql、redis、mongodb...)

mysql用户权限管理

Linux系统mysql数据库
用户的作用1.登录系统 2.启动进程 3.文件权限1.登录数据库 2.管理数据库
创建用户1.useradd 2.adduser1.grant 2.create user root@'localhost' 3.insert
删除用户1.userdel -r1.drop user root@'localhost' 2.delete
修改用户1.usermod1.update
查看用户1.id 2.passwd1.select user from mysql.user;

1.在MySQL中,用户是怎么定义的

#mysql中,定义一个用户是:用户名@'主机域'#用户名写法:用户名如果是字符:mysql> create user root@'10.0.0.1';用户名是数字需要加引号:mysql> create user '123'@'10.0.0.1';#主机域的写法:localhost127.0.0.1172.16.1.51db01172.16.1.%172.16.1.5%      #172.16.1.50-59172.16.%.%172.%.%.%%10.0.0.0/255.255.255.010.0.0.0/24					#可以设置,但是不生效

2.用户的管理

1)创建用户
mysql> create user root@'localhost';
mysql> grant all on *.* to root@'localhost' identified by '123';
mysql> insert ...
2)查看用户
mysql> select user,host from mysql.user;
3)修改用户密码
1.命令行使用mysqladmin修改密码
[root@db02 ~]# mysqladmin -uroot -p123 password 1234562.update修改用户密码
mysql> update mysql.user set password=PASSWORD('123') where user='root' and host='localhost';3.修改当前用户密码
mysql> set password=password('123456');4.grant修改密码
mysql> grant all on *.* to root@'localhost' identified by '123';
mysql> flush privileges;
4)删除用户
mysql> drop user qiudao@'10.0.0.0/24';
5)忘记root用户密码怎么办
1.停止数据库
systemctl stop mysqld2.跳过授权表和网络启动
mysqld_safe --skip-grant-tables --skip-networking &3.登录数据库
mysql4.修改密码
mysql> flush privileges;
mysql> grant all on *.* to root@'localhost' identified by '123';
mysql> flush privileges;5.退出重启数据库
mysqladmin -p123 shutdown
systemctl start mysql

3.权限的管理

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用户给我呗?

4.权限设置实践

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 用户名@'主机域';

 

http://www.lryc.cn/news/426673.html

相关文章:

  • 本地服务器物理机中redis设置、取消密码
  • 关于xilinx的FFTIP的使用和仿真
  • ant design pro 如何去保存颜色
  • 【Hadoop】建立圈内组件的宏观认识
  • C++:命名空间与输入输出
  • Azure DevOps Server 数据库日志已满,TF30042: The database is full
  • [C#]OpenCvSharp 实现Bitmap和Mat的格式相互转换
  • 【区块链+金融服务】基于区块链的供应链金融系统 | FISCO BCOS应用案例
  • AI语言大模型商业价值深度解析
  • 理解DDD领域驱动设计思想
  • 音频剪辑软件哪个好用?五大音频剪辑软件分享
  • 12.2 使用prometheus-sdk向pushgateway打点
  • HTTPS 详解
  • Microsoft Edge 使用方法与秘诀概览
  • 【视频】onvif、RTP、RTCP、SDP、RTSP、gb21818区别
  • 8-4 循环神经网络
  • Linux系统编程 --- 多线程
  • Grafana中的rate与irate以及histogram
  • 什么是网络安全态势感知
  • php 在app中唤起微信app进行支付,并处理回调通知
  • 高效同步与处理:ADTF流服务在自动驾驶数采中的应用
  • 【Arduino】ATmega328PB 连接 LSM6DS3 姿态传感器,并读数据(不确定 ESP 系列是否可行,但大概率是可行的)
  • live2d + edge-tts 优雅的实现数字人讲话 ~
  • 二进制安装php
  • 旧版Pycharm支持的python版本记录
  • java实现七牛云内容审核功能,文本、图片和视频的内容审核(鉴黄、鉴暴恐、敏感人物)
  • C++面试基础系列-struct
  • 代码随想录算法训练营 | 动态规划 part05
  • 英特尔XPU大模型应用创新
  • 仿Muduo库实现高并发服务器——socket网络通信模块