当前位置:网站首页>Safety foundation 2
Safety foundation 2
2022-07-27 23:05:00 【Hold the kitten】
Homework 1: In strict mode , Lead to MySQL5.7 Failed to create a new user by inserting the user table , How to modify strict mode
Strict mode introduction :
Strict mode control MySQL How to deal with illegal or missing input values SQL.
5.6 Of mode yes NO_ENGINE_SUBSTITUTION, In fact, it means a null value , It's equivalent to no mode settings , It can be understood as a relaxed model . If the setting is loose mode , So when we insert data , Even if it's given the wrong data , It may also be accepted , And don't report mistakes .
5.7 Of mode yes STRICT_TRANS_TABLES, That's the strict model . Developing 、 test 、 In production and other environments, most of them adopt strict mode .
Inquire about MySQL The pattern of :select @@sql_mode;

sql_model Introduction of value :
- NO_ZERO_IN_DATE: This pattern affects whether the month and day in the date are allowed to include 0. If this mode is enabled ,2016-01-00 It's not allowed , however 0000-02-01 Permissible
- NO_ZERO_DATE: Set the value ,mysql Database is not allowed to insert zero date
- ONLY_FULL_GROUP_BY: Appear in the SELECT sentence 、HAVING Conditions and ORDER BY Column in statement , Must be GROUP BY The columns may depend on GROUP BY Function columns of columns .
- NO_AUTO_VALUE_ON_ZERO: This value affects the insertion of self growing columns . By default , Insert 0 or NULL Represents the generation of the next self increasing value . If the user wants to insert a value of 0, And the column is self-growing , So this option works .
- STRICT_TRANS_TABLES: In this mode , If a value cannot be inserted into a transaction table , Then interrupt the current operation , No restrictions on non transaction tables .
- ERROR_FOR_DIVISION_BY_ZERO: stay INSERT or UPDATE In the process , If the data is divided by zero , It's a mistake, not a warning . If the mode is not given , So when the data is divided by zero ,MySQL return NULL.
- NO_AUTO_CREATE_USER: prohibit GRANT Create a user with a blank password .
- NO_ENGINE_SUBSTITUTION: If the required storage engine is disabled or not compiled , Then throw an error . When this value is not set , Replace... With the default storage engine , And throw an exception .
- PIPES_AS_CONCAT: take ”||” Treat as the concatenation operator of a string, not as the or operator , This sum Oracle The database is the same , And string concatenation function Concat Similar .
- ANSI_QUOTES: Enable ANSI_QUOTES after , You can't use double quotes to refer to strings , Because it's interpreted as an identifier .
How to modify strict mode :
1. Temporary session modification , Invalid closing session :set sql_mode = ' Modified value ' or set session sql_mode=' Modified value ';
2. The current service is modified , Starting the service again is invalid :set global sql_mode = ' Modified value ';
3. Permanent modification : stay my.cnf Add :
[mysqld] sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
And then restart mysql take effect .
Homework 2: Try to all Change it to select jurisdiction , And will * . * Change to specified database

Homework 3:16kb page Or other parameters at present , Is it possible to modify ?
B+ The characteristics of the tree :
- No data is stored on non leaf nodes , Store only key values , and B The tree node not only stores the key value , It also stores data .
- innodb Middle page The default size is 16KB, If you don't store data , Then more key values will be stored , The order of the corresponding tree ( The child tree of a node ) It will be more Big , The trees will be shorter and fatter , So we look up the data for disk IO The number of times will decrease again , The efficiency of data query will be faster .
- B+ All data in the tree index is stored in the leaf node , And the data is in order , Linked to the list . that B+ Trees make range lookups , Sort search , Group search and de duplication search become very simple .
- B+ The tree is made of N It exists in the form of a fork tree , This effectively reduces the height of the tree , You don't need a full table scan to find data , Looking down the root node layer by layer can Quickly find our target data ,
B+ The parameters of the tree can be modified .
- Page default 16KB
- File Header、Page Header Wait for a total of 102 Bytes
- Infimum + Supremum Accounting for 13 Bytes
- Record head 5 Bytes
- id Zhanwei int, Occupy 4 Bytes
- The offset of page directory accounts for 4 Bytes
- Index records that non leaf nodes can store = ( Page size - File Header - Page Header - ...) / ( Recording head + Primary key + Page offset )
- Data records that leaf nodes can store = ( Page size - File Header - Page Header - ...) / ( Primary key + Field + The offset of the next record )
Homework 4: understand MySQL Triggers and stored procedures for ?
1、 trigger : On the designated table ,(insert( Insert )、update( modify )、delete( Delete )) Event action , Trigger (After( after ) opportunity ,Before( Before )), Execute a designated group or group sql sentence . Simply put When we execute a sql At the time of statement , This article sql The execution of the statement will automatically trigger the execution of other sql sentence .
The four elements created by the trigger :
- Surveillance location (table)
- Monitoring events (insert/update/delete)
- Trigger time (before/after)
- Triggering event (insert/update/delete)
2、 stored procedure (Stored Procedure) It's a complex program stored in a database , A database object that can be called by an external program . Stored procedures are designed to accomplish specific functions SQL Statements set , Compiled, created and stored in a database , The user can specify the name of the stored procedure and give the parameters ( When needed ) To call execution . Stored procedures are very simple in mind , Database SQL Language level code encapsulation and reuse .
advantage :
- The operation is relatively stable .
- Reduce the interaction between business system and database , To reduce the coupling , Database interaction is faster .
shortcoming :
- MySQL Stored procedure and Oracle Is weaker than , The demand of the Internet industry changes rapidly, so it is less used .
- The migration of stored procedures is very difficult , Database cluster environment , It is also very difficult to ensure the consistency of stored procedure changes between Libraries .
- The maintenance process is also very troublesome .
Homework 5: substr Functions and substring Difference of function ?
SQL in substr The usage function :substr() Function returns part of a string .
- grammar : substr(string,start,length)
- string: The specified string to intercept .
- start: It's necessary , Specify where to start the string .
- Positive numbers : Start at the specified position of the string
- negative : Starting at the specified position at the end of the string
- 0: Start at the first character in a string
- length : Specify the length to intercept .
SQL in substring The usage function : Return character 、 Binary system 、 Part of the syntax of a text or image expression : substring ( expression, start, length )
difference :
- substring(start,stop) : The two parameters are the start and end positions , Include “ rise ”, barring “ stop ”, In terms of intervals, that is [start,stop)
- substr(start,length): The first parameter is the starting position , The second parameter is to intercept the length of the string
Homework 6: truncate and delete The difference between ?
- delete You can follow where Conditions ;truncate No terms
- delete After deletion, the number of affected lines is displayed ;truncate No affected rows are displayed
- delete It is data deletion one by one , Low efficiency ;truncate Is to delete the entire table , Creating an identical table structure , Efficient
- delete After deletion, the auto increment is based on the original maximum ;truncate Will start over
- deleter Except that it can be rolled back ;truncate Cannot be rolled back
- delete Deletion is slower than truncate
边栏推荐
- 物联网架构完全指南
- 51单片机内部外设:实时时钟(SPI)
- 2022/6/9 考试总结
- Excel only wants to visualize charts and make data move? Yes, come and watch (with a large number of templates to download)
- leetcode-470.用 Rand7() 实现 Rand10()
- Basic lighting of unity
- 智能家居浪潮来袭,如何让机器看懂世界 【结尾有资料】
- 2022/3/10 考试总结
- Quartus:Instantiation of ‘sdram_model_plus‘ failed. The design unit was not found.
- [NOI2018]归程(Kruskal重构树/可持久化并查集)
猜你喜欢

视频人体行为检测

You don't know about redis. Let me explain the underlying data structure of redis in detail

干货|语义网、Web3.0、Web3、元宇宙这些概念还傻傻分不清楚?(中)

Network development socket and UDP, TCP protocols

Cy3 fluorescent labeling antibody / protein Kit (10~100mg labeling amount)

Trends in software development in 2022

cron 表达式

Dry goods semantic web, Web3.0, Web3, metauniverse, these concepts are still confused? (medium)

图论的小技巧以及扩展

jvm组成及内存模型
随机推荐
Shandong football match
知乎数据分析训练营全能班
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
Cy3荧光标记抗体/蛋白试剂盒 (10~100mg标记量)
SparkSQL的UDF及分析案例,220726,,
[NOI2018] 冒泡排序(组合+卡特兰数+dp+树状数组)
你不知道的Redis那些事,我来详解Redis底层数据结构
It's time to say goodbye gracefully to nullpointexception
Exam summary on May 31, 2022
【云原生】k8s 部署redis集群
PyQt5快速开发与实战 4.9 对话框类控件
Five network management trends in 2022
2022/4/8 exam summary
4 轮拿下字节 Offer,面试题复盘
2022/6/5 exam summary
2022/5/18 exam summary
可能导致索引失效的原因
2022 / 4 / 11 exam summary
Fluorescence imaging of cle19 polypeptide in cells preparation of fluorescence quenching quantum dots of bovine serum albumin
JVM composition and memory model