mysql权限分类

USAGE --无权限,只有登录数据库,只可以使用test或test_*数据库

ALL --所有权限

select/update/delete/super/slave/reload --指定的权限

with grant option --允许把自己的权限授予其它用户(此用户拥有建立账号的权限)

权限级别:

1、. --全库、全表(mysql.user)

2、mysql.* --mysql库下所有表(某库中的所有表)(mysql.db)

3、mysql.user --mysql库中user表(单表)(mysql.table_priv)

4、mysql.user.host --mysql库中user表的host列(mysql.columns_priv)

用户权限:

user@localhost 本地

user@192.168.0.1 某一台主机

user@192.168.0.0/255.555.255.0 内网网段可以登录

user@% 任何机器上都可以登录

登录方式<本地|网络> with grant option ALL<select|insert|update|delete> .

1.新建一个本地帐号u01 可以创建用户可以执行所有的动作对所有库的所有表执行

bash 复制代码
create user 'u01'@'localhost' identified by '123';
grant all on *.* to 'u01'@'localhost' with grant option ; 

2.使用u01来 新建u02使用tcp方式登录 对db01库可以执行任何操作

bash 复制代码
create user 'u02'@'192.168.0.1' identified by '456';
grant all on db01.* to 'u02'@'192.168.0.1';
bash 复制代码
mysql -u u02 -p456 -h192.168.0.1 -P3306

3.新建u03 在客服端192.168.0.254 对db01库中t1表可以执行任何操作

bash 复制代码
grant all on db01.t1 to 'u03'@'192.168.0.254' identified by '789';

4.新建u04 在内网网段192.168.0.0/24 对db01.t1.id 可以执行任何操作

bash 复制代码
grant select,update(id,name) on db01.t1 to 'u04'@'192.168.0.0/24(掩码必须写完整的)' identified by '123456';
update mysql.user set host=192.168.0.0/255.255.255.0 where user='u04';
flush privileges;
grant select,update(id,name) on db01.t1 to 'u04'@'192.168.0.0/255.255.255.0'

5.新建u05 在任何机器上可以登录 对db02全库操作

bash 复制代码
grant all on db02.* to 'u05'@'%' identified by 'redhat';

取消权限revoke

bash 复制代码
revoke all on *.* from 'u01'@'localhost';
delete from mysql.user where user regexp '^u.*';
flush privileges;

不进数据库在外面查看表信息

bash 复制代码
mysql  -uroot -p123 -e "select user,host,password from mysql.user"
相关推荐
iRayCheung几秒前
virtualbox安装的ubuntu系统跑numpy报错
linux·ubuntu·numpy
snow@li1 分钟前
DevOps:深入理解 DevOps(2026版)
运维·devops
Safeploy安策数据4 分钟前
等保测评总卡壳?PCI加密卡如何破解政务云与金融合规难题
运维·网络·安全
Dlrb12114 分钟前
Linux系统编程-信号量(线程同步机制)
linux·条件变量·互斥锁·信号量·线程同步
Mr -老鬼6 分钟前
2026移动端自动化平台横向对比指南:15+主流平台深度评测,开发者选型必备
运维·自动化·easyclick·移动测试
cui_ruicheng7 分钟前
MySQL(三):库操作与表操作
数据库·mysql·oracle
闪电悠米8 分钟前
黑马点评-Redis 消息队列-02_list_pubsub_limits
java·数据库·ide·redis·缓存·list·intellij-idea
无限进步_9 分钟前
Linux进程等待——wait、waitpid与僵尸进程
linux·运维·服务器·开发语言
suoyue_zhan14 分钟前
SQL经典案例之数据库的CTE递归循环使用
数据库·sql
2401_8346369914 分钟前
Linux集群技术-高可用与负载均衡实战解析
linux·运维·负载均衡