当前位置:网站首页>MySQL user authority summary [user authorization required]
MySQL user authority summary [user authorization required]
2022-06-11 14:56:00 【Code knower】
see :
- 《MySQL Will know 》
- https://www.cnblogs.com/Richardzhu/p/3318595.html
One 、MySQL User permissions
There is a project recently , During the development process, the database is directly installed on the Alibaba cloud server , Connect locally to the Alibaba cloud server MySQL You can't just root User connection , Each database operation uses the newly created user to interact with the user .
In the use of non root User's time , Perform local sql file , You need some permissions , such as SELECT,INSERT,UPDATE,DELETE,CREATE And so on , Let's take a note of this , Later, during development , You can view the record of this article , Just apply it directly .
add to MySQL The benefits of users and setting permissions : new SQL The user is not allowed to access other SQL User's library or table , You can't even use SELECT sentence . new SQL Users must be explicitly granted permissions , To execute the corresponding operation .
Two 、 Introduction to user permissions
1. Permission level
- overall situation : Can manage the whole MySQL
- database : Can manage the specified database
- Data sheet : Can manage the specified tables of the specified database
- Field : You can manage the specified fields of the specified table of the specified database
Permissions stored in mysql Library user,db,tables_priv,columns_priv,procs_priv In these system tables , stay MySQL Load the instance into memory after it starts , Implement user permission control .
2. Permission implementation
MySQL The permission implementation is divided into two sections for verification :
The first stage : The server will first check whether the user is allowed to connect . First from user In the table Host,User,Password this 3 Determine connected ip、 user name 、 Whether the password exists , Verify if it exists .
The second stage : After authentication , Permission judgment is required for each request initiated by the user , according to user,db,tables_priv,columns_priv,procs_priv Verify in order of . Check the global permission table first user, If user The corresponding permissions in are Y, Then this user's permission to all databases is Y, Will no longer check db, tables_priv,columns_priv; If N, Then to db Check the specific database corresponding to this user in table , And get the db In Chinese, it means Y Authority ; If db In Chinese, it means N, Then check tables_priv The specific table corresponding to this database in . And so on .
3. Authority distribution
MYSQL How to distribute the authority of , What permissions can be set for the table , What permissions can be set for columns, etc , This can be illustrated by a table in the official document :
| Authority distribution | Possible set permissions |
|---|---|
| Table permissions | ‘Select’, ‘Insert’, ‘Update’, ‘Delete’, ‘Create’, ‘Drop’, ‘Grant’, ‘References’, ‘Index’, ‘Alter’ |
| Column permissions | ‘Select’, ‘Insert’, ‘Update’, ‘References’ |
| Process authority | ‘Execute’, ‘Alter Routine’, ‘Grant’ |
The above are also some of the most commonly used permissions . More permission settings , You can directly view the authority description in the official document .
4. Query permission table
To view the user MySQL user
select user,host from mysql.user;
see root The user's permissions in the permission table
The previous table is N, The system will check the next table .
# Y It means you have permission ,N Means no authority
# 1.mysql.user surface (all)
select * from mysql.user where user='root';
# 2.mysql.db surface (empty)
select * from mysql.db where user='root';
# 3.mysql.tables_priv (empty)
select * from mysql.tables_priv where user='root';
# 4.mysql.colums_priv surface (empty)
select * from mysql.columns_priv where user='root';
# 5.mysql.procs_priv (empty)
select * from mysql.procs_priv where user='root';
3、 ... and 、 User authority practice
All of the following operations are intended to root user , stay mysql In the library .
1. View user permission information
View the current user
select user();
see MYSQL Who are the users
select user,host from mysql.user;
View the permission information that has been authorized to the user
show grants for 'pdh'@'%';
2. User creation and Authorization
Just briefly MySQL The authorized users of : ‘user_name’@‘host_name’( In the middle @ Symbolic connection ). among user_name Represents the user name ,host_name Represents the host , It can be ipv4 and ipv6 Format ,% Indicates that all hosts can access . The following lists different formats to represent different hosts :
| project | Value | |
|---|---|---|
| user_name | host_name | explain |
| ‘pdh’ | ‘198.51.100.177’ | pdh, Only from now on ip Connect |
| ‘pdh’ | ‘198.51.100.%’ | pdh, from 198.51.100 Any host in the subnet |
| ‘pdh’ | ‘%’ | pdh, Any host can be connected to |
establish MySQL Users and permissions *
# 1. Use CREATE Create user , And then authorize
# 1.1 establish pdh user , Set the password to 123456, It doesn't have permission
CREATE USER 'pdh'@'%' IDENTIFIED BY '123456';
# 1.2 grant pdh Query and add test Permissions for Libraries
grant select,insert,update,delete,create,alter on test.* to 'pdh';
# 2. Use GRANT Create users and authorize test All operations of the library
grant all privileges on test.* to 'pdh'@'%' identified by "123456" with grant option;
The above instructions explain
1. ALL PRIVILEGES It means all rights , You can also use select、update Such as permissions .
2. ON Used to specify which libraries and tables permissions are for
3. test.* Express test All tables of the library
4. TO Means to give permission to a user .
5. 'pdh'@'%' Express pdh user , The host to %. The host can be IP、IP paragraph 、 Domain name and %
6. IDENTIFIED BY Specify the user's login password
7. WITH GRANT OPTION This option means that the user can authorize his own permissions to others
Refresh the permissions
Use this command to make permissions work , For permission table user、db、host When we do update perhaps delete When updating, be sure to perform permission refresh .
flush privileges;
View and modify permissions
View current user permissions
show grants;
Recycling permissions
# Recycling alter jurisdiction
revoke alter on test.* from 'pdh'@'%';
# Reclaim all permissions
revoke all privilegeson test.* from 'pdh'@'%';
边栏推荐
- Lippon instrument software intern interview
- Hamad application layout scheme 03 of hashicopy (run a job)
- 为什么需要public static void main(String[ ] args)这个方法?
- Raspberry school literacy
- 如何做好自媒体?这几个步骤你做对了吗?
- Implementation of gray-scale publishing scheme for microservice architecture based on gateway and Nacos
- Live800: several ways for intelligent customer service to improve customer experience
- [SystemVerilog interface] ~ interface
- 2021 go developer survey
- 清北力压耶鲁,MIT蝉联第一,2023QS世界大学排名最新发布
猜你喜欢

深度剖析「圈组」关系系统设计 | 「圈组」技术系列文章

Cartoon: interesting "cake cutting" problem

uniapp设置页面跳转效果 - navigateTo切换效果 - 全局animationType动画

Task manager based on Qt development

社交软件Soul撤回IPO申请:上市只差临门一脚 腾讯是大股东

高数_第6章无穷级数__马克劳林级数

Analyse approfondie de la conception du système relationnel du Groupe de cercles

线程池的七个参数与拒绝策略

Ali, tell me about the application scenarios of message oriented middleware?

Raspberry pie obtains the function of network installation system without the help of other devices
随机推荐
In the "ten billion blue ocean" database, each player can find a boat | c-position face-to-face
Individual income tax rate table
Hashicopy之nomad应用编排方案03(运行一个job)
百度某离职员工跳槽字节被判赔107万元;苹果谷歌微软拟“干掉”密码;传吉利已收购魅族|Q资讯
Knowledge of affairs
Hashicopy之nomad应用编排方案02
A former employee of Baidu was awarded 1.07 million yuan for job hopping; Apple, Google and Microsoft plan to "kill" the password; It is said that Geely has acquired Meizu | Q information
英伟达研发主管:AI 是如何改进芯片设计的?
2021 年度 Go 开发者调查
Current situation and future development trend of global and Chinese metal casting robot market
Managing technology debt in a microservice architecture
简单的C语言版本通讯录
System.out.println()方法使用需要注意哪些问题
PowerShell主架构师:我用业余时间开发项目,表现优秀反而被微软降级了
one hundred and twenty-three thousand four hundred and sixty-five
Vscode virtual environment running file reported an error importerror: DLL load failed: the specified module could not be found
Hashicopy之nomad应用编排方案05(访问web页面)
In depth research and analysis report on global and Chinese plant extract products market
Hashicopy之nomad应用编排方案01
Flutter 3.0 was officially released: it stably supports 6 platforms, and byte jitter is the main user