DC's blog DC's blog
首页
  • 计算机基础
  • linux基础
  • mysql
  • git
  • 数据结构与算法
  • axure
  • english
  • docker
  • opp
  • oop
  • 网络并发编程
  • 不基础的py基础
  • 设计模式
  • html
  • css
  • javascript
  • jquery
  • UI
  • 第一次学vue
  • 第二次学vue
  • Django
  • drf
  • drf_re
  • 温故知新
  • flask
  • 前后端不分离

    • BBS
    • 订单系统
    • CRM
  • 前后端部分分离

    • pear-admin-flask
    • pear-admin-django
  • 前后端分离

    • 供应链系统
  • 理论基础
  • py数据分析包
  • 机器学习
  • 深度学习
  • 华中科大的网课
  • cursor
  • deepseek
  • 杂文
  • 罗老师语录
  • 关于我

    • me
  • 分类
  • 归档
GitHub (opens new window)

DC

愿我一生欢喜,不为世俗所及.
首页
  • 计算机基础
  • linux基础
  • mysql
  • git
  • 数据结构与算法
  • axure
  • english
  • docker
  • opp
  • oop
  • 网络并发编程
  • 不基础的py基础
  • 设计模式
  • html
  • css
  • javascript
  • jquery
  • UI
  • 第一次学vue
  • 第二次学vue
  • Django
  • drf
  • drf_re
  • 温故知新
  • flask
  • 前后端不分离

    • BBS
    • 订单系统
    • CRM
  • 前后端部分分离

    • pear-admin-flask
    • pear-admin-django
  • 前后端分离

    • 供应链系统
  • 理论基础
  • py数据分析包
  • 机器学习
  • 深度学习
  • 华中科大的网课
  • cursor
  • deepseek
  • 杂文
  • 罗老师语录
  • 关于我

    • me
  • 分类
  • 归档
GitHub (opens new window)
  • 计算机基础

  • linux基础

  • mysql

    • 基础

      • install_db
      • db_command
      • imp_knowledge
      • table_field
      • table_relation
      • permissions
        • 用户管理
          • 创建和删除用户
          • 修改用户和IP
          • 修改密码
        • 授权管理
          • 授权
          • 权限
          • 查看授权
          • 取消授权
      • single_query
      • multi_query
      • query_practice
      • pymysql
      • just_know
      • 补充(1)
      • 补充(2)
    • 进阶

  • git

  • 数据结构与算法

  • axure

  • english

  • docker

  • IT_Need
  • mysql
  • 基础
DC
2023-01-29
目录

permissions

用户和权限信息都放在这张 mysql.user表内!

# 账户、密码、限制连接者所在的IP地址
select user,authentication_string,host from  mysql.user;
1
2

# 用户管理

# 创建和删除用户

create user '用户名'@'连接者的IP地址' identified by '密码';

create user egon1@127.0.0.1 identified by 'root123';
drop user egon1@127.0.0.1;

# %表示可以匹配值 可以是127.0.0.1、127.0.0.2、127.0.0.3 ...
create user egon2@'127.0.0.%' identified by 'root123';
drop user egon2@'127.0.0.%';

# egon3@'%' 表示可以在任意的IP地址下通过egon3这一账户连接mysql
create user egon3@'%' identified by 'root123';
drop user egon3@'%';

# 建议 '账号'@'IP'都加上引号! 
create user 'egon4'@'%' identified by 'root123';
drop user 'egon4'@'%';
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 修改用户和IP

rename user '用户名'@'IP地址' to '新用户名'@'IP地址';

rename user egon1@127.0.0.1 to egon1@localhost;
rename user 'egon1'@'127.0.0.1' to 'egon1'@'localhost';
1
2

# 修改密码

set password for '用户名'@'IP地址' = Password('新密码')

set password for 'egon4'@'%' = Password('123123');

-- ★修改root账户密码:
alter user'root'@'localhost' identified by '新密码';
flush privileges;
1
2
3
4
5

# 授权管理

# 授权

grant 权限 on 数据库.表 to '用户'@'IP地址' *代表所有!

数据库名.*            数据库中的所有
数据库名.表名          指定数据库中的某张表
数据库名.存储过程名     指定数据库中的存储过程
*.*                  所有数据库
1
2
3
4
-- 用户egon拥有所有数据库的所有权限
grant all privileges on *.* TO 'egon'@'localhost';

-- 用户egon拥有数据库day26的所有权限
grant all privileges on day26.* TO 'egon'@'localhost';

-- 用户egon拥有数据库day26中info表的所有权限 
-- 账号'egon'@'localhost'就只能查到day26数据库 只能查到info表
grant all privileges on day26.info TO 'egon'@'localhost';  

-- 用户egon拥有数据库day26中info表的查询权限
grant select on day26.info TO 'egon'@'localhost';

-- 用户egon拥有数据库day26所有表的查询和插入权限
grant select,insert on day26.* TO 'egon'@'localhost';      

grant all privileges on day26db.* to 'egon4'@'%';
注意:flush privileges;   -- 将数据读取到内存中,从而立即生效。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 权限

all privileges  除grant外的所有权限
select          仅查权限
select,insert   查和插入权限
...
usage                   无访问权限
alter                   使用alter table
alter routine           使用alter procedure和drop procedure
create                  使用create table
create routine          使用create procedure
create temporary tables 使用create temporary tables
create user             使用create user、drop user、rename user和revoke  all privileges
create view             使用create view
delete                  使用delete
drop                    使用drop table
execute                 使用call和存储过程
file                    使用select into outfile 和 load data infile
grant option            使用grant 和 revoke
index                   使用index
insert                  使用insert
lock tables             使用lock table
process                 使用show full processlist
select                  使用select
show databases          使用show databases
show view               使用show view
update                  使用update
reload                  使用flush
shutdown                使用mysqladmin shutdown(关闭MySQL)
super                   使用change master、kill、logs、purge、master和set global。
												还允许mysqladmin调试登陆
replication client      服务器位置的访问
replication slave       由复制从属使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# 查看授权

show grants for '用户'@'IP地址'

show grants for 'egon'@'localhost';
show grants for 'egon4'@'%';
1
2

# 取消授权

revoke 权限 on 数据库.表 from '用户'@'IP地址'

revoke ALL PRIVILEGES on day26.* from 'egon'@'localhost';

revoke ALL PRIVILEGES on day26db.* from 'egon4'@'%';
注意:flush privileges;   -- 将数据读取到内存中,从而立即生效。
1
2
3
4

一般情况下,在很多的正规公司. 数据库都是由DBA来统一进行管理.DBA为每个项目的数据库创建用户.并赋予相关的权限.

table_relation
single_query

← table_relation single_query→

最近更新
01
deepseek本地部署+知识库
02-17
02
实操-微信小程序
02-14
03
教学-cursor深度探讨
02-13
更多文章>
Theme by Vdoing | Copyright © 2023-2025 DC | One Piece
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式