mysql权限设置

mysql -h localhost -u User -p passWord DataBase -e "sql"
# -h 连接服务器ip
# -u 用户
# -p 密码
# DataBase 连接数据库
# -e 执行sql

1. 新建用户

① CREATE USER

create user 'userName'@'localhost' identified by 'passWord';
-- 如果只指定用户名部分,localhost 则默认为‘%’,即为对所有的主机开放权限
-- passWord 为明文密码,不指定则登录无需密码

② 插入user表新增用户

insert into mysql.user(host,user,authentication_string) values ('localhost','userName',md5('passWord'));

在这里插入图片描述

2. 删除用户

drop user userName[@'localhost'] [,userName ];
-- drop user userName 删除mysql用户
-- drop user 'userName'@'localhost' 删除用户和主机部分
delete from mysql.user where host='localhost' and user='userName'

3. 修改密码

-- 修改root用户密码
update mysql.user set authentication_string=md5("passWord") where user='root' and host='localhost';
flush privileges;
-- 需要重新刷新加载权限

4. 权限控制

① 添加权限

grant privType [(columns)] [,privType  [(columns)]]
on [objectType] teble1 [,table2]
to 'userName'@'localhost' [with grant option]
-- privType 表示权限类型
-- columns 表示列,不指定则为全表
-- objectType 指定授权作用对象 TABLE(表)、FUNCTION(函数)和PROCEDURE(存储过程)
-- userName 授权用户
-- with 关键字后可以跟一个或多个参数,① GRANT OPTION:被授权的用户可以将这些权限赋予别的用户。② MAX_QUERIES_PER_HOUR count:设置每个小时可以执行count次查询。③ MAX_UPDATES_PER_HOUR count:设置每小时可以执行count次更新。④ MAX_CONNECTIONS_PER_HOUR count:设置每小时可以建立count个连接。⑤ MAX_USER_CONNECTIONS count:设置单个用户可以同时建立count个连接。

在这里插入图片描述

② 权限回收

revoke all privType [(columns)] [,privType [(columns)]]
on table1 [,table2]
form 'userName'@'localhost';

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值