当前位置:网站首页> MySQL数据库用户权限管理
MySQL数据库用户权限管理
2022-06-09 15:05:00 【1024问】
1、用户管理
1.1、创建用户
1.2、删除用户
1.3、修改用户密码
2、权限管理
2.1、授予权限 grant
2.2、取消权限 revoke
2.3、刷新权限 flush
3、密码丢失的解决方案
1、用户管理mysql的用户信息保存在了mysql.user中:
select * from mysql.user\G*************************** 5. row *************************** Host: localhost User: root Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 password_expired: N password_last_changed: 2020-02-05 22:46:27 password_lifetime: NULL account_locked: N Create_role_priv: Y Drop_role_priv: Y Password_reuse_history: NULL Password_reuse_time: NULLPassword_require_current: NULL User_attributes: NULL主要字段:
主机名和用户名共同组成复合主键Host 主机名,允许访问的客户端,*代表所有客户端都可以访问User 用户名1.1、创建用户方式一:直接使用root用户在mysql.user中插入记录(不推荐)
方式二:使用创建用户的SQL指令
基本语法:
create user 用户 identified by 明文密码-- 用户 用户名@主机地址-- 主机地址: '' 或者 %示例:
create user 'user1'@'%' identified by '123456';-- 查看mysql.user表中是否存在新用户select user, host from mysql.user where user = 'user1';+-------+------+| user | host |+-------+------+| user1 | % |+-------+------+简化版创建用户,谁都可以访问,不需要密码,不安全
create user user2;1.2、删除用户user和host具有唯一性
基本语法:
drop user 用户名@host;示例:
mysql> drop user 'user1'@'%';Query OK, 0 rows affected (0.01 sec)mysql> select user, host from mysql.user where user = 'user1';Empty set (0.00 sec)1.3、修改用户密码需要使用函数对密码进行加密password()
方式一:使用专门的修改密码指令
基本语法:
set password for 用户 = password(明文密码);set password for 'user1'@'%' = password(654321);-- mysql5.7后续版本,8.0可用alter user 'user1'@'%' identified by '654321';方式二:使用更新语法
基本语法:
update mysql.user set password = password(明文密码) where user = '' and host = '';update mysql.user set password = password('123456') where user = 'user1' and host = '%';-- 8.0报错update mysql.user set authentication_string = password('123456') where user = 'user1' and host = '%';2、权限管理分为三类:
数据权限:增删改查 select update delete insert
结构权限:结构操作(表操作) create drop
管理权限:权限管理 create user、grant、revoke, 管理员
2.1、授予权限 grant将权限分配给指定用户
基本语法:
grant 权限列表 on 数据库/*.表名/* to 用户权限列表 使用逗号间隔,all privileges 代表全部权限
所有数据库 *.*
某个数据库:数据库.*
单表:数据库.表名
-- 分配权限 不需要刷新,马上生效grant select on mydatabase.my_student to 'user1'@'%';2.2、取消权限 revoke基本语法:
revoke 权限列表 /all privileges on 数据库/*.表/* from 用户-- 回收权限,不需要刷新,马上生效revoke all privileges on mydatabase.my_student from 'user1'@'%';2.3、刷新权限 flush将操作的具体内容同步到对应的表中
基本语法:
flush privileges;3、密码丢失的解决方案如果忘记root用户的密码
# 停止服务mysql.server stop;# 停止不了可以直接杀死进程ps aux|grep mysqlkill <pid># 重新启动服务,跳过权限mysqld --skip-grant-tables# 直接无用户名登录mysql非常危险,任何客户端不需要任何用户信息都可以直接登录,而且是root权限
修改root密码:
alter user 'root'@'localhost' identified by '123456'; 修改完后,关闭mysql服务器,重启
到此这篇关于MySQL数据库用户权限管理的文章就介绍到这了,更多相关MySQL 权限管理内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- [cloud native | kubernetes] in depth understanding of pod (VI)
- Simple example of mongoose connecting multiple databases
- AE script - grid reference line golden section line generation tool guidesup! 2.2 active version
- Google installs the impression note clipping plug-in
- 4年经验来面试20K的测试岗,连基本功都不会,还不如去招应届生
- 【五、反向代理及其相关配置】
- Hongmeng porting i.mx6ull (VIII) memory mapping (based on imx6ull)
- Applet turntable lottery assembly
- How greatsql is a popular open source database in China
- 一年进账34.46亿,又一个福建老乡要IPO了
猜你喜欢

InfoQ geek media's 15th anniversary solicitation of papers | design practice of micro service architecture in the cloud native Era

Mysql+C# EF6间的连接

Validate palindrome string

【二、虚拟主机和域名解析】

BAT和FAANG的时代翻篇儿了,谁来接棒?

How many points can you get if the programmer's college entrance examination paper is exposed?

王兴张勇徐雷,谁能问鼎本地电商?

不要假装怀念Kindle

酒店长租是一门好生意吗?

新冠病毒的最终解药
随机推荐
ZeroSSL 支持给 IP 地址申请 SSL 证书了,但有瑕疵!
Taoist friends! What is the expiration policy of redis?
文化和自然遗产日,任务空投来了
Hongmeng transplantation i.mx6ull (V) overview of transplantation
Triangular constant strain element (CST) derived from area coordinates
名片微信小程序错误版本2
QT MSVC compiler Chinese problem solving, Chinese garbled and unable to compile normally
薪酬不变,每周只上四天班,英国试行全球最大规模“四天工作制”
How many points can you get if the programmer's college entrance examination paper is exposed?
新冠病毒的最终解药
【论文】Cascade RPN: Delving into high-quality region proposal network with Adaptive Convolution
@Enablefeignclients annotation source code analysis
单调队列优化Dp例题
AE脚本-网格参考线黄金分割线生成工具 GuidesUp! 2.2激活版
不要假装怀念Kindle
Hongmeng porting i.mx6ull (VIII) memory mapping (based on imx6ull)
GaussDB(DWS)功能及配套工具丨【这次高斯不是数学家】
Some tool functions commonly used in JS projects
鸿蒙移植i.mx6ull(六) Kconfig_GCC_Mkefile
Hongmeng porting i.mx6ull (11) storage device driver (based on imx6ull)