Mysql common data types and instance descriptions (study Note 1) bitsCN.com
1. Mysql in windows
Net start mysql [start]
Net stop mysql [stop]
Quit [exit mysql command line]
/C [cancel the input command]
Select version (), current_date ()
Mysql version number, current date (year, month, and day, for example)
Now () current time (year, month, day, hour, minute, second, for example, 08:29:56)
User () User
2. a simple calculator
Select sin (pi ()/6), 100/3;
3. you do not have to give a command in one line. long commands can be entered into multiple lines. Mysql determines where the statement ends by looking for a termination semicolon instead of the end of the input line.
Mysql status
|
Prompt |
Description |
|
Mysql> |
Ready to accept new commands |
|
-> |
Wait for the next line of the multi-line command |
|
'> |
Wait for the next line, and wait for the end of the string starting with single quotes ("'") |
|
" |
Wait for the next line and wait for the end of the string starting with double quotation marks (') |
|
` |
Wait for the next line and wait for the end of the string starting with the reverse oblique point ("'") |
|
/* |
Wait for the next line and wait for the end of comments starting /* |
Note: When ',', 'is entered, a new command cannot be entered if the corresponding Terminator is not entered.
4. Mysql common column types
① String data type
|
Data type |
Description |
|
Char |
A fixed-length string of 1 to characters. The length must be specified at creation. otherwise, Mysql is assumed to be char (1) |
|
Varchar |
Variable Length. The maximum length of the whole body is 65,532 bytes. if it is specified as varchar (n) at creation, the variable length string (n <= 65535) character set with 0 to n characters can be stored. |
|
Tinytext |
Same as text, up to 255 bytes |
|
Mediumtext |
Same as text, but up to 16 k |
|
Text |
Variable-length text with a maximum length of 64 KB |
|
Longtext |
Same as text, but the maximum length is 4 GB |
|
Enum |
A string of a predefined set consisting of up to 64 K strings. |
|
Set |
Accept 0 or multiple strings in a predefined set consisting of up to 64 K strings |
Numeric data type
|
Data type |
Description |
|
Tinyint |
Integer, supporting-128-127 (if unsigned, 0-255) of 1 byte |
|
Smallint |
Integer, supporting-32768-32767 (unsigned, 0-65535) 2 bytes |
|
Mediumint |
-8388608-8388607 (undesigned 0-) 3 bytes 223
-223-223-1 |
|
Int |
231 4 bytes |
|
Bigint |
8 bytes |
|
Float |
Single-precision floating point value |
|
Double |
Double-precision floating point value |
|
Boolean |
Boolean |
|
Decimal |
Variable-precision floating point value |
|
Peal |
4-byte floating point value |
|
Bit |
It is a field, 1-64 bits. (the function is tinyint before mysql5) |
Date and time data types
|
Data type |
Description |
|
DATE |
Represents the date from 1000-01-01 to 9999-12-31, in YYYY-MM-DD format) |
|
DATETIME |
Combination of DATE and TIME |
|
TIMESTAMP |
Functions are the same as DATETIME (but the range is small) |
|
TIME |
Format: HH: MM: SS |
|
YEAR |
It is represented by two digits in the range of 70 (1970)-69 (2069), and four digits in the range of 1901-2155. |
Binary data
|
Data type |
Description |
|
TINYBLOB |
Blob can contain up to 255 bytes. |
|
BLOB |
64kb |
|
MEDIUMBLOB |
16 MB |
|
LONGBLOB |
4 GB |
5. Supplement related data types
Optional attribute unsigned and zerofill in column declaration
Tinyint (4) by default)
It makes sense only when zerofill is given in parentheses.
For example, if zerofill tinyint (5) is defined and 1 is inserted, 00001 is inserted.
Decimal type:
Floating point (not standard), Fixed point (4 or 8 bytes are Complex)
Float (M, D) M is not the total number of digits. the number of digits after the D decimal point
For example, the float (6, 4) range is
-9999.99-9999.99
688.896 is inserted into 688.90
1, 3, 7, 9
2, 4, 6, 8, 5 carry
Fixed point type:
Decimal (M, D)
There is little difference between data inserted and stored data.
Character type:
Char (M) M represents the length of characters that can be accommodated, not the size of a byte. a Chinese character z occupies three bytes, and it is still a character (subject to encoding ),When the inserted data is smaller than the specified length, spaces are removed when it is filled with spaces. if the inserted data is at the end of the inserted data with spaces, the space at the end of the inserted data will be lost when it is saved, when the value is smaller than M, it also accounts for M characters, and the utilization rate is <= 100%;
Varchar (M) smaller than M, up to 65535 bytes (ascii).N characters, n <= M. it must use 1-2 bytes to record the actual storage space. if there are spaces at the end, utilization = n/(n + 1 ~ 2 bytes) <100%. if the value is less than 255, one byte is used. if the value is greater than, two bytes are used.
Proof of the above differences:
Create table t2
Create table 'T2 '(
'Id' int (10) unsigned not null auto_increment,
'Name' char (7) not null,
'Pass' varchar (8) not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = utf8
Insert data with spaces at the end
Insert into t2 (name, pass)
Value ('HK ', 'HK ');
Retrieve data
Select concat (name ,'! '), Concat (pass ,'! ') From t2;
Will find
Differences between Char and varchar
1. Char: 1-255 fixed length string Varchar: 0-65535
2. the actual occupied space is different from the utilization efficiency
3. processing trailing spaces
Char (no default length is 1). varchar must be given a length when creating a table. tinytext cannot be given a length. text cannot be given a length, the default value cannot be set for text data.
Modify column data attributes
Alter table 't1 'change 'id' INT (10) unsigned not null AUTO_INCREMENT
Alter table name change field name field column declaration (including field name)
Unsigned must be placed after the type
BitsCN.com