当前位置:网站首页>Summary of the most complete MySQL data types in history (Part 2)
Summary of the most complete MySQL data types in history (Part 2)
2022-07-25 01:12:00 【51CTO】
Then continue to sort out the above , Above we wrote about
time type , Then we'll write the date and time type date type .
date type
date Type is used when only date values are required , There is no time part , When storing, you need 3 byte .
The date format is YYYY-MM-DD. among YYYY Indicate year ,MM Represents the month ,DD Means day .
(1) With 'YYYY-MM-DD' perhaps 'YYYYMMDD' Date in string format , The value range is '1000-01-01' ~ '9999-12-3' ; For example, the input '2022-12-31' perhaps ‘20221231’, The date when the database is inserted is 2022-12-31;
(2) With ‘YY-MM-DD’ perhaps ‘YYMMDD’ Date in string format , ad locum ‘YY’ Represents the annual value of two digits . Dates with two digit year values can be confusing , Because I don't know the century .mysql Use the following rules to interpret two digit year values :‘00~69’ The annual value of the range is converted to 2000-2069,'70-99' The annual value of the range is converted to 1970~1999.
(3) With YY-MM-DD perhaps YYMMDD Date in numeric format , Similar to the front ,00~69 The annual value of the range is converted to 2000~2069,70~99 The annual value of the range is converted to 1970~1999.
(4) Use CURRENT_DATE perhaps NOW(), Insert current system date .
for instance :
Create a file called yunweijia_4 Data sheet for ;
Insert some values into the table ;
Then check the results :
Another example :
Delete data table yunweijia_4 Data in ;
Insert data into the table ;
Check the results :
Another example :
Old rules , First delete the data in the table
Insert data into table ;
Check the results :
Another example :
Delete data in table ;
Insert the current time of the system :
View results :
CURRENT_DATE Only the current date value is returned , Not including the time part ;NOW() Function returns date and time values , When saving to the database , Only the date part is retained .
datetime type
DATETIME Type is used for values that need to contain both date and time information , When storing, you need 8 byte . The date format is ‘YYYY-MM-DD HH:MM:SS’. among ,YYYY Indicate year ,MM Represents the month ,DD Means day ,HH For hours ,MM Represents minutes ,SS For seconds . In giving DATETIME When assigning a field of type , You can insert data using either a string type or a number type , As long as meet DATETIME The date format can be .
(1) With ‘YYYY-MM-DD HH:MM:SS’ perhaps ‘YYYYMMDDHHMMSS’ Value in string format , The value range is ‘1000-01-01 00:00:00’~‘9999-12-3 23:59:59’;
(2) With ‘YY-MM-DD HH:MM:SS’ perhaps ‘YYMMDDHHMMSS’ Date in string format , ad locum YY Represents the annual value of two digits . Same as before ,‘00~69’ The annual value of the range is converted to ‘2000~2069’,‘70~99’ The annual value of the range is converted to ‘1970~1999’.
(3) With YYYYMMDDHHMMSS perhaps YYMMDDHHMMSS Date and time in numeric format .
TIMESTAMP type
TIMESTAMP The display format is the same as DATETIME identical , The display width is fixed at 19 Characters , The date format is YYYY-MM-DD HH:MM:SS, When storing, you need 4 byte .TIMESTAMP The value range of column is less than DATETIME Value range of , by ‘1970-01-01 00:00:01’UTC~‘2038-01-1903:14:07’UTC. among ,UTC(Coordinated Universal Time) For world standard time , So when inserting data , Ensure that it is within the legal value range .
Be careful :
because
datetime The type and TIMESTAMP It is quite different from the above usage , So here are no more examples .
Text string type
The string type is used to store string data , In addition to storing string data , Other data can also be stored , Such as binary data of pictures and sounds .
mysql Support two types of string data : Text strings and binary strings ;
Text strings can be used for case sensitive or case insensitive string comparison , You can also search for pattern matching .
stay mysql in , The text string type refers to :
- CHAR
- VARCHAR
- TEXT
- ENUM
- SET
See the following table for details :

VARCHAR and TEXT The type and BLOB All are Variable length type , Its storage requirements Depends on the actual length of the column value ( Use... In the previous table L Express ), Rather than depending on the maximum possible size of the type .
for example , One VARCHAR(10) The maximum length that the column can save is 10 Character string , The actual storage needs to be the length of the string L add 1 byte ( Record the length of the string ). For characters “abcd”,L yes 4 The storage requirements are 5 byte .
CHAR and VARCHAR type
CHAR(M) Is a fixed length string , Specify the string column length when defining . Fill in the space on the right when saving , To reach the specified length .M Column length ,M The range is 0~255 Characters .
for example :CAHR(4) Defines a fixed length character string , The maximum number of characters it contains is 4. When the retrieved CHAR When the value of , The trailing space will be deleted .
VARCHAR(M) Is a variable length string ,M Indicates the maximum column length .M The range is 0~65535.VARCHAR The maximum actual length of is determined by the size of the longest line and the character set used , The actual space occupied is the actual length of the string plus 1.
for example :VARCAHR(50) Defines a maximum length of 50 String , If the inserted string is only 10 Characters , Then the actual stored string is 10 Characters and a string ending character .VARCHAR When the corresponding value is saved and retrieved, the trailing space remains .
Let's take a look at CHAR(4) and VARCHAR(4) What is the difference between storage :

We can see from the comparison results in the above figure ,CHAR(4) The fixed length is defined as 4 The column of , No matter how long the stored data is , The space occupied is 4 Bytes ;VARCHAR(4) The number of bytes occupied by the defined column is the actual length plus 1;
But the query is different , We can look at it through the following example ;
for instance :
Create a file called yunweijia_5 Data sheet for ;
Insert some data into this data table ;
Check the results :
There's a problem here , The document above describes ,char The space will be deleted when saving ,varchar The space at the end will be reserved , But from the perspective of its own practice , Whether it's char still varchar Have deleted the space at the end .
TEXT type
TEXT Column holds non binary strings , Such as the content of the article 、 Comments, etc .
When saving or querying TEXT Column value , Do not delete trailing spaces .
Text Types are divided into 4 Kind of :
For the rest, go to VX official account “ Operation and maintenance home ” , reply “196” see .
------ “ Operation and maintenance home ” , reply “196” ------
------ “ Operation and maintenance home ” , reply “196” ------
------ “ Operation and maintenance home ” , reply “196” ------
Weifang operation and Maintenance Engineer Recruitment , The development prospect of hardware operation and maintenance engineers , Personal planning of operation and maintenance engineer , Shenzhen Sunshine rain dew operation and maintenance engineer , Public institutions recruit operation and maintenance engineers ;
Qianxin operation and Maintenance Engineer Interview , Sany Heavy Industry system operation and maintenance engineer , Operation and maintenance engineer interview questions , Operation and maintenance engineer of Environmental Engineering ;
What direction do operation and maintenance engineers have , Hangzhou operation and maintenance engineer recruits Ali , Bridge operation and maintenance engineer , Desktop operation and maintenance engineer training plan .
边栏推荐
- Tiktok iqiyi announced cooperation, long and short video handshake and reconciliation?
- Verification of Kirchhoff's law and Multisim Simulation (engineering documents attached)
- 7.24 party notice
- Multi table query of SQL
- Amd epyc 9654 Genoa CPU cache test exposure L1 bandwidth up to 30tb/s
- 进程的几种状态
- The position of the nth occurrence of MySQL in the string
- Google Earth engine - 1980 present global pressure, temperature, wind and other data sets
- SAP Spartacus - progressive web applications, progressive web applications
- Several states of the process
猜你喜欢

Advanced multithreading (Part 2)

Automated test series selenium three kinds of waiting for detailed explanation

C # "learning code snippet" - recursively obtain all files under the folder
![Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation](/img/e1/51f750d355b248ab84e10f0e134271.png)
Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation

Human cell prosci 4-1BB ligand recombinant protein scheme

Top priority of dry goods: common indicators and terms in data analysis!

Visual studio code installation package download slow & Installation & environment configuration & new one-stop explanation

Invitation letter | "people, finance, tax" digital empowerment, vigorously promote retail enterprises to achieve "doubling" of economies of scale

Implementing DDD based on ABP -- domain logic and application logic

7.18 - daily question - 408
随机推荐
How SAP Spartacus redefines login component
Detailed explanation of zero length array in C language (1) [information at the end of the article]
Unity panel control
Pychart exits pytest mode (run pytest in mode)
Codeworks round 650 (Div. 3) ABCD solution
The position of the nth occurrence of MySQL in the string
7.20 - daily question - 408
[27. Expression evaluation (infix expression)]
JS convert pseudo array to array
Interview questions
基于ABP实现DDD--领域逻辑和应用逻辑
Batchinsert avoid inserting duplicate data ignor
Divide 300000 bonus! Deeperec CTR model performance optimization Tianchi challenge is coming
Simple use of mongodb database
Visual studio code installation package download slow & Installation & environment configuration & new one-stop explanation
C recursively obtains all files under the folder and binds them to the treeview control
Prosci anti-CD22 antibody epratuzum28 flow cytometry display
Which automation tools can double the operation efficiency of e-commerce?
C # "learning code snippet" - recursively obtain all files under the folder
Service address dynamic awareness of Nacos registry