当前位置:网站首页>[MySQL must know and know] trigger | permission management
[MySQL must know and know] trigger | permission management
2022-07-25 14:31:00 【CPT】
List of articles
trigger
For manual operation of data , It's easy to forget one step , Cause data loss .
Trigger operation
-- Create Syntax
CREATE TRIGGER Trigger Name {BEFORE|AFTER} {
INSERT|UPDATE|DELETE}
ON Table name
FOR EACH ROW expression ;
- Table name : Represents the object monitored by the trigger .
- INSERT|UPDATE|DELETE: Indicates the event triggered .INSERT Indicates that... Is triggered when a record is inserted ;UPDATE Indicates that... Is triggered when the record is updated ;DELETE Indicates that... Is triggered when a record is deleted .
- BEFORE|AFTER: Indicates the trigger time .BEFORE Indicates that... Is triggered before the event ;AFTER In the event of Trigger later .
-- Check triggers
SHOW TRIGGERS \G;
-- Delete trigger
drop trigger Trigger Name ;


- If the trigger is executed , Statement error , Then it won't execute .
Advantages and disadvantages of flip flops
advantage
- Triggers ensure data integrity , The data is consistent , There will be no contradiction .
- Triggers can help us log operations
- Triggers can also be used before manipulating data , Check the validity of the data .
shortcoming - One of the biggest problems with triggers is poor readability , If an error occurs , Its error information is particularly difficult to find , It is basically similar to ordinary , Maintenance costs are high , The solution is to maintain a complete database design document .
Rights management
- user : Personnel role : A collection of permission assignments
- Appropriate permission settings , It can ensure the security of data , This is crucial .
role
- The role is in MySQL 8.0 New features introduced in , Equivalent to a collection of permissions . The purpose of introducing roles is to facilitate management Manage users with the same permissions .
- After creating the role , By default, this role does not have any permissions , We need to authorize the role .
-- Create the role The role of In single quotation marks
create role role_id
CREATE ROLE 'manager'@'localhost';
-- Role name is “manager”, The host that the role can log in yes “localhost”
-- If you don't write the hostname ,MySQL The default is wildcard “%”, This means that this account can be logged on from any host Record database .
-- Authorize roles
grant jurisdiction on Table name to The role of ;
select read-only
select,insert,delete,update Additions and deletions
-- View role permissions
show grant for Character name ;
-- Delete the role
drop role role id;
-- Activate role
set global activate_all_roles_on_login=ON;
- MySQL Created in After the role , The default is not activated , It needs to be activated before it can be assigned to the user .

user
-- Create user You must specify a password
CREATE USER user name [IDENTIFIED BY password ];
-- Authorize users
grant role_id to user_id; -- You can create the permission of the role above Assign to user
grant jurisdiction on Table name to user_id; -- Direct empowerment
-- View user permissions
show grant for user_id;
-- Delete user
drop user user_id;

Summary
- Roles are sets of permissions . Delete The character , Then the user will lose all the permissions obtained through this role
- When the character was just created , The default is not activated , You need to activate... Manually , Can only be Use .
- Try to use the database's own role and user mechanism To control access rights , Don't use it easily Root account number .
边栏推荐
- Problems and extensions of the monocular depth estimation model featdepth in practice
- Ten common application scenarios of redis
- Realsense-Ros安装配置介绍与问题解决
- opencv视频跟踪「建议收藏」
- Sqli labs installation environment: ubuntu18 php7
- Software testing -- 1. Outline of software testing knowledge
- How to make a set of code fit all kinds of screens perfectly?
- 基于浏览器的分屏阅读
- maya建模练习
- 轻松入门自然语言处理系列 12 隐马尔可夫模型
猜你喜欢

Niuke multi school E G J L

Matplotlib data visualization three minutes entry, half an hour enchanted?
![Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]](/img/b6/62a346174bfa63fe352f9ef7596bfc.png)
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]

Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction

Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders

D2. picking carrots (hard version) (one question per day)

IDEA报错 Failed to determine a suitable driver class

~5 new solution of CCF 2021-12-2 sequence query

用GaussDB(for Redis)存画像,推荐业务轻松降本60%

VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
随机推荐
swiper 一侧或两侧露出一小部分
Pytorch training code writing skills, dataloader, Einstein logo
Detailed explanation of nat/napt address translation (internal and external network communication) technology [Huawei ENSP]
Apple failed to synchronize on its mobile terminal, so it exited the login. As a result, it could not log in again
Realsense-Ros安装配置介绍与问题解决
sudo rosdep init Error ROS安装问题解决方案
Famous handwritten note taking software recruit CTO · coordinate Shenzhen
Realize a family security and environmental monitoring system (I)
Can the variable name be in Chinese? Directly fooled people
Easy entry natural language processing series 12 hidden Markov models
苹果手机端同步不成功,退出登录,结果再也登录不了
gson与fastjson
The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level
~5 new solution of CCF 2021-12-2 sequence query
如何让一套代码完美适配各种屏幕?
idea正则表达式替换(idea正则搜索)
Two Sum
关于左值和右值的一些问题总结[通俗易懂]
From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
VS2017大型工厂ERP管理系统源码 工厂通用ERP源码