当前位置:网站首页>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
边栏推荐
- 2022/3/10 考试总结
- Analysis of cloud native application security organization structure
- 视频人体行为检测
- 投资22亿美金!格科微12英寸CIS制造项目落户上海临港
- Excel only wants to visualize charts and make data move? Yes, come and watch (with a large number of templates to download)
- If there is no reference ground at all, guess if you can control the impedance?
- Cloudcompare & PCL platform convex hull method to calculate crown volume
- Exam summary on May 13, 2022
- 2022/5/18 exam summary
- Six employees have been confirmed! Samsung closed the turtle tail mobile phone factory for the third time!
猜你喜欢

Quartus:Instantiation of ‘sdram_model_plus‘ failed. The design unit was not found.

It's time to say goodbye gracefully to nullpointexception

数据仓库项目从来不是技术项目

Take byte offer in four rounds and answer the interview questions

网络开发套接字以及UDP、TCP协议

Solve the problem that the last bit of IP address access is odd and even, or even and odd (the problem encountered when the cloud encryption machine connects to the cloud server, the whole process is

2022年软件开发的趋势

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

Buuctf brushes eleven questions (05)

The significance of enterprise digital transformation, digital transformation is not a choice
随机推荐
Summary of exam on May 17, 2022
The epidemic has spread to 28 states in the United States: more than 100000 employees such as apple and Microsoft work from home, and iphone11 is almost out of stock!
Cy3荧光标记抗体/蛋白试剂盒 (10~100mg标记量)
Introduction to the paper | distributed graph simulation
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
2022/5/13 考试总结
2022/3/10 考试总结
Pyqt5 rapid development and practice 4.9 dialog controls
8000字讲透OBSA原理与应用实践
初中三年回忆录
Feed stream application reconfiguration - Architecture
2022/5/18 考试总结
catch all in one draft! Introduction to 10 data visualization software
2022 review plan of joint provincial election
Solve the problem that the last bit of IP address access is odd and even, or even and odd (the problem encountered when the cloud encryption machine connects to the cloud server, the whole process is
浅谈数仓的数据治理
一篇搞定Redis中的BigKey问题
Convnext:a convnet for the 2020s - model Brief
Do you want to be dismissed? Let's take a look at the "exit tips" of programmers
PX4模块设计之十三:WorkQueue设计