JSON
M
M
ZEROFILL
UNSIGNED
SIGNED
SERIAL
SERIAL DEFAULT VALUE
UNSIGNED
NO_UNSIGNED_SUBTRACTION
M
M
TINYINT[(
M
)]
[UNSIGNED] [ZEROFILL]
-128
0
TINYINT(1)
MySQL的> SELECT IF(0, 'true', 'false');
|;if(0,true,false);| |虚假| >;MySQL SELECT IF(1, 'true', 'false');
段(1,| if true,false);| | True | >;MySQL SELECT IF(2, 'true', 'false');
的;(2 | if true,false);TRUE;| | |
TRUE
1
mysql>SELECT IF(0 = FALSE, 'true', 'false');
+--------------------------------+ | IF(0 = FALSE, 'true', 'false') | +--------------------------------+ | true | +--------------------------------+ mysql>SELECT IF(1 = TRUE, 'true', 'false');
+-------------------------------+ | IF(1 = TRUE, 'true', 'false') | +-------------------------------+ | true | +-------------------------------+ mysql>SELECT IF(2 = TRUE, 'true', 'false');
+-------------------------------+ | IF(2 = TRUE, 'true', 'false') | +-------------------------------+ | false | +-------------------------------+ mysql>SELECT IF(2 = FALSE, 'true', 'false');
+--------------------------------+ | IF(2 = FALSE, 'true', 'false') | +--------------------------------+ | false | +--------------------------------+
2
0
SMALLINT[(
M
)]
[UNSIGNED] [ZEROFILL]
-32768
0
MEDIUMINT[(
M
)]
[UNSIGNED] [ZEROFILL]
-8388608
0
INT[(
M
)]
[UNSIGNED] [ZEROFILL]
-2147483648
0
INTEGER[(
M
)]
[UNSIGNED] [ZEROFILL]
INT
BIGINT[(
M
)]
[UNSIGNED] [ZEROFILL]
-9223372036854775808
0
SERIAL
BIGINT
BIGINT
DOUBLE
BIGINT
DOUBLE
BIGINT
BIGINT
MIN(
col_name
)MAX(
col_name
)col_name
BIGINT
BIGINT
-
+
*
BIGINT
DECIMAL[(
M
[,D
])]
[UNSIGNED] [ZEROFILL]
M
D
M
D
M
DECIMAL
D
D
M
UNSIGNED
+, -, *, /
DECIMAL
DEC[(
M
[,D
])]
[UNSIGNED] [ZEROFILL]NUMERIC[(
M
[,D
])]
[UNSIGNED] [ZEROFILL]FIXED[(
M
[,D
])]
[UNSIGNED] [ZEROFILL]
FLOAT[(
M
,D
)]
[UNSIGNED] [ZEROFILL]
-3.402823466E+38
0
3.402823466E+38
M
D
M
D
UNSIGNED
FLOAT
DOUBLE[(
M
,D
)]
[UNSIGNED] [ZEROFILL]
-1.7976931348623157E+308
0
1.7976931348623157E+308
M
D
M
D
UNSIGNED
DOUBLE
PRECISION[(
M
,D
)]
[UNSIGNED] [ZEROFILL]REAL[(
M
,D
)]
[UNSIGNED] [ZEROFILL]
DOUBLE
REAL_AS_FLOAT
REAL
FLOAT
DOUBLE
FLOAT(
p
)
[UNSIGNED] [ZEROFILL]
p
FLOAT
DOUBLE
p
FLOAT
M
D
p
DOUBLE
M
D
FLOAT
DOUBLE
FLOAT(
p
)
DATE
DATETIME
TIME
DATETIME
TIMESTAMP
type_name
fsp
type_name
TIME
DATETIME
TIMESTAMP
fsp
create table T1(t(3小时),DT DateTime(6));
fsp
TIMESTAMP
DATETIME
'1000-01-01'
DATE
DATE
'1000-01-01 00:00:00.000000'
DATETIME
DATETIME
fsp
DATETIME
ON UPDATE
'1970-01-01
00:00:01.000000'
TIMESTAMP
TIMESTAMP
'0000-00-00
00:00:00'
TIMESTAMP
fsp
TIMESTAMP
explicit_defaults_for_timestamp
explicit_defaults_for_timestamp
ON
UPDATE CURRENT_TIMESTAMP
TIMESTAMP
TIMESTAMP
NULL
explicit_defaults_for_timestamp
TIMESTAMP
TIMESTAMP
INSERT
UPDATE
TIMESTAMP
NULL
DEFAULT
CURRENT_TIMESTAMP
TIMESTAMP
TIMESTAMP
'-838:59:59.000000'
TIME
TIME
fsp
YEAR
YEAR
2155
YEAR
YEAR(2)
YEAR(4)
SUM()
AVG()
选择sec_to_time(sum(time_to_sec( time_col
)))从 tbl_name
;选择from_days(和(to_days( date_col
)))从 tbl_name
;
CREATE
TABLE
ALTER TABLE
CHAR
VARCHAR
TEXT
CHAR
VARCHAR
TEXT
ENUM
SET
CHARACTER SET
CREATE TABLE t ( c1 VARCHAR(20) CHARACTER SET utf8, c2 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs );
c1
c2
CHARACTER SET
CHARSET
CHARACTER SET binary
CHAR
BINARY
VARCHAR
VARBINARY
TEXT
BLOB
ENUM
SET
创建表(C1 varchar(10)字符集的文本字符集的二进制二进制,C2、C3型(A,B,C)字符集的二进制);
CREATE TABLE t ( c1 VARBINARY(10), c2 BLOB, c3 ENUM('a','b','c') CHARACTER SET binary );
BINARY
ASCII
UNICODE
CHAR
VARCHAR
TEXT
ENUM
SET
BINARY
[NATIONAL] CHAR[(
M
)]
[CHARACTER SET charset_name
]
[COLLATE
collation_name
]
M
M
M
CHAR
PAD_CHAR_TO_FULL_LENGTH
CHAR
CHARACTER
NATIONAL CHAR
NCHAR
CHAR
CHAR BYTE
BINARY
CHAR(0)
CHAR(0) NULL
''
[NATIONAL] VARCHAR(
M
)
[CHARACTER SET charset_name
]
[COLLATE
collation_name
]
M
M
VARCHAR
VARCHAR
VARCHAR
VARCHAR
VARCHAR
VARCHAR
CHARACTER VARYING
NATIONAL VARCHAR
VARCHAR
NVARCHAR
NATIONAL VARCHAR
BINARY
CHAR
M
M
VARBINARY
VARCHAR
M
TINYTEXT
[CHARACTER SET
charset_name
]
[COLLATE
collation_name
]
TEXT
TINYTEXT
BLOB
BLOB
M
BLOB
M
TEXT[(
M
)]
[CHARACTER SET charset_name
]
[COLLATE
collation_name
]
TEXT
TEXT
M
TEXT
M
BLOB
MEDIUMBLOB
MEDIUMTEXT
[CHARACTER SET
charset_name
]
[COLLATE
collation_name
]
TEXT
MEDIUMTEXT
BLOB
LONGBLOB
LONGBLOB
LONGTEXT
[CHARACTER SET
charset_name
]
[COLLATE
collation_name
]
TEXT
LONGTEXT
LONGTEXT
ENUM('
value1
','value2
',...)
[CHARACTER SET charset_name
]
[COLLATE
collation_name
]
'
value1
'value2
NULL
ENUM
ENUM
ENUM
M
<= 255 and (M
w
) <= 1020, wherew
SET('
value1
','value2
',...)
[CHARACTER SET charset_name
]
[COLLATE
collation_name
]
'
value1
'value2
SET
SET
SET
M
<= 255 and (M
w
) <= 1020, wherew
INTEGER
SMALLINT
DECIMAL
NUMERIC
FLOAT
REAL
DOUBLE PRECISION
INT
INTEGER
DEC
FIXED
DECIMAL
DOUBLE
DOUBLE PRECISION
REAL
DOUBLE PRECISION
REAL_AS_FLOAT
BIT
MyISAM
MEMORY
InnoDB
INTEGER
SMALLINT
MEDIUMINT
TINYINT | -128 | 0 | 127 | 255 | |
SMALLINT | -32768 | 0 | 32767 | 65535 | |
MEDIUMINT | -8388608 | 0 | 8388607 | 16777215 | |
INT | -2147483648 | 0 | 2147483647 | 4294967295 | |
BIGINT | -263 | 0 | 263-1 | 264-1 |
DECIMAL
NUMERIC
DECIMAL
DECIMAL
DECIMAL
工资小数(5,2)
5
DECIMAL(5,2)
-999.99
DECIMAL(
M
)M
DECIMAL(
M
,0)M
M
DECIMAL
DECIMAL
FLOAT
FLOAT
FLOAT
FLOAT(
M
,D
)M
D
M
D
M
D
M
D
-999.9999
FLOAT(7,4)
FLOAT
BIT
M
M
M
b'
value
'value
b'10000000'
BIT(
M
)M
BIT(6)
INT(4)
INT
SMALLINT(3)
SMALLINT
32767
ZEROFILL
INT(4) ZEROFILL
0005
ZEROFILL
UNION
ZEROFILL
UNSIGNED
INT
-2147483648
0
UNSIGNED
ZEROFILL
AUTO_INCREMENT
AUTO_INCREMENT
value
value
1
0
NULL
NO_AUTO_VALUE_ON_ZERO
NULL
NOT NULL
NULL
AUTO_INCREMENT
AUTO_INCREMENT
t1
创建表T1(I1 tinyint、I2 tinyint unsigned);
mysql>SET sql_mode = 'TRADITIONAL';
mysql>INSERT INTO t1 (i1, i2) VALUES(256, 256);
ERROR 1264 (22003): Out of range value for column 'i1' at row 1 mysql>SELECT * FROM t1;
Empty set (0.00 sec)
mysql>SET sql_mode = '';
mysql>INSERT INTO t1 (i1, i2) VALUES(256, 256);
mysql>SHOW WARNINGS;
+---------+------+---------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------+ | Warning | 1264 | Out of range value for column 'i1' at row 1 | | Warning | 1264 | Out of range value for column 'i2' at row 1 | +---------+------+---------------------------------------------+ mysql>SELECT * FROM t1;
+------+------+ | i1 | i2 | +------+------+ | 127 | 255 | +------+------+
ALTER TABLE
LOAD DATA
INFILE
UPDATE
INSERT
BIGINT
MySQL的> SELECT 9223372036854775807 + 1;
错误1690(22003):bigint值超出范围”(922337203685477580 1)”
mysql> SELECT CAST(9223372036854775807 AS UNSIGNED) + 1;
+-------------------------------------------+
| CAST(9223372036854775807 AS UNSIGNED) + 1 |
+-------------------------------------------+
| 9223372036854775808 |
+-------------------------------------------+
DECIMAL
MySQL的> SELECT 9223372036854775807.0 + 1;
--------------------------- | 9223372036854775807.0 1 | --------------------------- | 9223372036854775808.0 | ---------------------------
UNSIGNED
MySQL的> SET sql_mode = '';
查询行,0行受影响(0秒)MySQL > SELECT CAST(0 AS UNSIGNED) - 1;
错误1690(22003):bigint无符号值超出范围”(铸造(0为无符号)- 1)”
NO_UNSIGNED_SUBTRACTION
MySQL的> SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
MySQL的> SELECT CAST(0 AS UNSIGNED) - 1;
------------------------- |铸造(0为无符号)-1 | ------------------------- | -1 | -------------------------
UNSIGNED
NO_UNSIGNED_SUBTRACTION
DATE
TIME
DATETIME
TIMESTAMP
YEAR
TIMESTAMP
'98-09-04'
'04-09-98'
70-99
00-69
TIME
TIME
'2009-11-31'
ALLOW_INVALID_DATES
DATE
DATETIME
'2009-01-00'
DATE_SUB()
DATE_ADD()
NO_ZERO_IN_DATE
'0000-00-00'
NULL
NO_ZERO_DATE
NULL
'0'
DATE
DATETIME
TIMESTAMP
NO_ZERO_DATE
DATE | '0000-00-00' |
TIME | '00:00:00' |
DATETIME | '0000-00-00 00:00:00' |
TIMESTAMP | '0000-00-00 00:00:00' |
YEAR | 0000 |
DATE
TIMESTAMP
DATETIME
DATE
DATE
'YYYY-MM-DD'
'9999-12-31'
DATETIME
'YYYY-MM-DD
HH:MM:SS'
'9999-12-31
23:59:59'
TIMESTAMP
'1970-01-01
00:00:01'
DATETIME
DATETIME
'YYYY-MM-DD
HH:MM:SS[.fraction]'
'1000-01-01
00:00:00.000000'
TIMESTAMP
'2038-01-19
03:14:07.999999'
TIMESTAMP
TIMESTAMP
TIMESTAMP
time_zone
DATE
TIMESTAMP
'0000-00-00'
'10:11:12'
'2010-11-12'
'0000-00-00'
'2004-04-31'
ALLOW_INVALID_DATES
TIMESTAMP
'0000-00-00 00:00:00'
00-69
70-99
TIME
'HHH:MM:SS'
'-838:59:59'
TIME
TIME
TIME
'-838:59:59.000000'
TIME
'11:12'
'00:11:12'
1112
'00:11:12'
12
TIME
'850:00:00'
'838:59:59'
'00:00:00'
TIME
'00:00:00'
TIME
YEAR
YEAR(4)
YEAR(2)
YEAR(4)
YEAR
1901
0000
YEAR
1901
'1901'
1
1
70
YEAR
2069
1999
'0'
'0'
'70'
YEAR
2069
1999
0
0000
'0'
YEAR
NOW()
YEAR
YEAR(2)
YEAR(2)
YEAR(4)
YEAR(2)
YEAR(2)
ER_INVALID_YEAR_COLUMN_LENGTH
MySQL的> CREATE TABLE t1 (y YEAR(2));
错误1818(hy000):只支持一年或一年(4)柱。
ALTER TABLE
REPAIR TABLE
CHECK TABLE
YEAR(2)
YEAR(2)
YEAR(2)
YEAR(4)
YEAR(2)
YEAR(2)
YEAR(2)
YEAR(4)
ALTER TABLE
REPAIR TABLE
CREATE TABLE t1 (ycol YEAR(2) NOT NULL DEFAULT '70');
ALTER TABLE
修改表T1的力量;
ALTER TABLE
YEAR(2)
ALTER
TABLE
REPAIR TABLE
YEAR(2)
YEAR(4)
REPAIR TABLE
--skip-write-binlog
YEAR(2)
YEAR(2)
YEAR(4)
YEAR(2)
YEAR(4)
ALTER TABLE
YEAR(2)
YEAR(4)
TIMESTAMP
DATETIME
TIMESTAMP
DATETIME
CURRENT_TIMESTAMP
explicit_defaults_for_timestamp
TIMESTAMP
NULL
NULL
DEFAULT
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP()
NOW()
LOCALTIME
LOCALTIME()
LOCALTIMESTAMP
LOCALTIMESTAMP()
DEFAULT CURRENT_TIMESTAMP
TIMESTAMP
DATETIME
DEFAULT 0
DEFAULT 0
NO_ZERO_DATE
TRADITIONAL
NO_ZERO_DATE
TIMESTAMP
DATETIME
DEFAULT CURRENT_TIMESTAMP
CREATE TABLE t1 ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
DEFAULT
DEFAULT
CURRENT_TIMESTAMP
创建表T1(TS时间戳默认current_timestamp,DT DateTime默认current_timestamp);
CREATE TABLE t1 ( ts TIMESTAMP DEFAULT 0, dt DATETIME DEFAULT 0 );
ON UPDATE CURRENT_TIMESTAMP
CREATE TABLE t1 ( ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, dt DATETIME DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP );
ON UPDATE CURRENT_TIMESTAMP
TIMESTAMP
NULL
创建表T1(TS1的时间戳更新current_timestamp,默认0 TS2时间戳空更新current_timestamp --默认为空);
DATETIME
NOT
NULL
创建表T1(DT1 DateTime更新current_timestamp --默认为空,不current_timestamp DT2 DateTime更新默认0空);
TIMESTAMP
DATETIME
explicit_defaults_for_timestamp
TIMESTAMP
ON
UPDATE CURRENT_TIMESTAMP
TIMESTAMP
explicit_defaults_for_timestamp
ON UPDATE
CURRENT_TIMESTAMP
TIMESTAMP
explicit_defaults_for_timestamp
DEFAULT
NULL
NULL
NULL
CURRENT_TIMESTAMP
NOW()
CREATE TABLE t1 ( ts1 TIMESTAMP DEFAULT 0, ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); CREATE TABLE t2 ( ts1 TIMESTAMP NULL, ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); CREATE TABLE t3 ( ts1 TIMESTAMP NULL DEFAULT 0, ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
TIMESTAMP
ts1
t1
NOT NULL
t2
ts1
NULL
t2
ts1
ts1
NULL
t3
NULL
TIMESTAMP
DATETIME
创建表T1(TS时间戳(6)默认current_timestamp(6)更新current_timestamp(6));
CREATE TABLE t1 ( ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(3) );
explicit_defaults_for_timestamp
TIMESTAMP
NULL
TIMESTAMP
NULL
DEFAULT
NULL
TIMESTAMP
DEFAULT NULL
TIMESTAMP
NULL
TIMESTAMP
CREATE TABLE t ( ts1 TIMESTAMP NULL DEFAULT NULL, ts2 TIMESTAMP NULL DEFAULT 0, ts3 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP );
TIMESTAMP
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
NOW()
TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
创建表(TS时间戳零违约current_timestamp);
TIMESTAMP
DEFAULT CURRENT_TIMESTAMP
t2
创建表T1(TS时间戳零违约的0000-00-00 00:00:00”);创建表T2(TS时间戳空默认为空);
TIMESTAMP
插入的T2值(current_timestamp);插入T1值(now());
explicit_defaults_for_timestamp
TIMESTAMP
NULL
TIMESTAMP
NULL
CURRENT_TIMESTAMP
NOW()
TIME
DATETIME
TIMESTAMP
type_name
(fsp
)type_name
TIME
DATETIME
TIMESTAMP
fsp
create table T1(t(3小时),DT DateTime(6));
fsp
TIME
DATE
TIMESTAMP
MySQL的> CREATE TABLE fractest( c1 TIME(2), c2 DATETIME(2), c3 TIMESTAMP(2) );
查询行,0行受影响(0.33秒)MySQL > INSERT INTO fractest VALUES
> ('17:51:04.777', '2014-09-08 17:51:04.777', '2014-09-08 17:51:04.777');
查询行,1行的影响(0.03秒)MySQL > SELECT * FROM fractest;
------------- ------------------------ ------------------------ | C1 C2 C3 | | | ------------- ------------------------ ------------------------ | 17:51:04.78 | 2014 09 08 17:51:04.78 | 2014 09 08 17:51:04.78 | ------------- ------------------------ ------------------------ 1行在设定(0.00秒)
sql_mode
NOW()
DATE '
str
'str
str
DATE
DATETIME
TIMESTAMP
TIMESTAMP
'2038-01-19 03:14:07'
DATE
DATETIME
TIMESTAMP
DATE
TIME
CURRENT_DATE()
TIME
'23:59:59'
'2012-01-01'
TIME
'24:00:00'
DATETIME
TIMESTAMP
'2012-01-02
00:00:00'
TIME
DATE
'2012-01-02'
DATE
DATETIME
DATE
DATETIME
DATETIME
CAST()
date_col
= CAST(datetime_col
日期)
TIME
DATETIME
TIME(
N
)DATETIME(
N
)N
N
N
MySQL的> SELECT CURTIME(), CURTIME()+0, CURTIME(3)+0;
——————| curtime()()| curtime | curtime(3 0 0 |)——————| 09∶28∶00 | 92800 | 92800.887 |——>——MySQL。 SELECT NOW(), NOW()+0, NOW(3)+0;
--------------------- ---------------- -------------------- |现在(现在)|()(3)0 0 |现在| --------------------- ---------------- -------------------- | 2012 - 08 - 15 9:28点| 20120815092800 | 20120815092800.889 | --------------------- ---------------- --------------------
DATETIME
DATE
TIMESTAMP
00-69
70-99
YEAR
YEAR(4)
2000
2000
'00'
ORDER BY
YEAR
MIN()
MAX()
YEAR
YEAR
CHAR
VARCHAR
BINARY
VARBINARY
BLOB
TEXT
ENUM
SET
CHAR
CHAR
CHAR(30)
CHAR
CHAR
PAD_CHAR_TO_FULL_LENGTH
VARCHAR
CHAR
CHAR
VARCHAR
VARCHAR
CHAR
CHAR(4)
latin1
CHAR(4) | VARCHAR(4) | |||
---|---|---|---|---|
'' | ' ' | '' | ||
'ab' | 'ab ' | 'ab' | ||
'abcd' | 'abcd' | 'abcd' | ||
'abcdefgh' | 'abcd' | 'abcd' |
InnoDB
utf8mb4
CHAR(4)
CHAR
MySQL的> CREATE TABLE vc (v VARCHAR(4), c CHAR(4));
查询好,为受影响的行(0.01秒)MySQL > INSERT INTO vc VALUES ('ab ', 'ab ');
查询行,1行的影响(0秒)MySQL > SELECT CONCAT('(', v, ')'), CONCAT('(', c, ')') FROM vc;
|,意图,意图concat((V)是| concat()(,,C,|),意图,意图|)(AB)(AB)| |,意图,意图在1行集(0.06秒)
CHAR
INFORMATION_SCHEMA
COLLATIONS
CHAR
TEXT
LIKE
MySQL的> CREATE TABLE names (myname CHAR(10));
查询行,0行受影响(0.03秒)MySQL > INSERT INTO names VALUES ('Monty');
查询行,1行的影响(0秒)MySQL > SELECT myname = 'Monty', myname = 'Monty ' FROM names;
+------------------+--------------------+| myname = 'Monty' | myname = 'Monty ' |+------------------+--------------------+| 1 | 1 |+------------------+--------------------+1 row in set (0.00 sec)mysql>SELECT myname LIKE 'Monty', myname LIKE 'Monty ' FROM names;
我的意思是,我的意思是,我的意思是,我的意思是我的意思。
'a'
BINARY
CHAR
VARCHAR
BINARY
CHAR
VARCHAR
VARBINARY
BINARY
CHAR BINARY
BINARY
CHAR(5) BINARY
utf8mb4
binary
BINARY
BINARY
0x00
DISTINCT
0x00
< space.
BINARY(3)
'a \0'
'a\0\0'
VARBINARY
DISTINCT
0x00
< space.
'a'
BINARY
BINARY
MySQL的> CREATE TABLE t (c BINARY(3));
查询好,为受影响的行(0.01秒)MySQL > INSERT INTO t SET c = 'a';
查询行,1行的影响(0.01秒)MySQL > SELECT HEX(c), c = 'a', c = 'a\0\0' from t;
+--------+---------+-------------+| HEX(c) | c = 'a' | c = 'a\0\0' |+--------+---------+-------------+| 610000 | 0 | 1 |+--------+---------+-------------+1 row in set (0.09 sec)
VARBINARY
BLOB
BLOB
TINYBLOB
MEDIUMBLOB
TEXT
TEXT
LONGTEXT
BLOB
TEXT
BLOB
TEXT
TEXT
TEXT
'a '
BLOB
VARBINARY
VARCHAR
TEXT
VARBINARY
VARCHAR
BLOB
CHAR
VARCHAR
BINARY
_bin
LONG
MEDIUMTEXT
BLOB
TEXT
BLOB
max_sort_length
max_sort_length
max_sort_length
max_sort_length
MySQL的> SET max_sort_length = 2000;
MySQL的> SELECT id, comment FROM t
-> ORDER BY comment;
BLOB
MEMORY
BLOB
SELECT *
BLOB
max_allowed_packet
max_allowed_packet
BLOB
BLOB
FILE
ENUM
ENUM
ENUM
ENUM
CREATE TABLE shirts ( name VARCHAR(40), size ENUM('x-small', 'small', 'medium', 'large', 'x-large'));INSERT INTO shirts (name, size) VALUES ('dress shirt','large'), ('t-shirt','medium'), ('polo shirt','small');SELECT name, size FROM shirts WHERE size = 'medium';+---------+--------+| name | size |+---------+--------+| t-shirt | medium |+---------+--------+UPDATE shirts SET size = 'small' WHERE size = 'large';COMMIT;
'medium'
VARCHAR
SELECT
mysql> SELECT * FROM tbl_name
WHERE enum_col
=0;
NULL
ENUM('Mercury',
'Venus', 'Earth')
NULL | NULL |
'' | |
'Mercury' | |
'Venus' | |
'Earth' |
ENUM
ENUM
mysql> SELECT enum_col
+0 FROM tbl_name
;
ENUM
ENUM
ENUM
LOAD DATA
'0'
'2'
2
numbers ENUM('0','1','2')
2
'2'
'3'
mysql>INSERT INTO t (numbers) VALUES(2),('2'),('3');
mysql>SELECT * FROM t;
+---------+ | numbers | +---------+ | 1 | | 2 | | 2 | +---------+
ENUM
SHOW COLUMNS
FROM
tbl_name
LIKE
'enum_col
'Type
ENUM
''
ENUM
ENUM
ENUM
NULL
ENUM
ENUM
'a'
NULL
ORDER
BY
ENUM
ORDER BY
CAST(
col
AS CHAR)col
CREATE TABLE
CONCAT
创建表的大小(大小枚举(小,concat('med ','ium '),'大'));
SET @mysize = 'medium'; CREATE TABLE sizes ( size ENUM('small', @mysize, 'large') );
TINYINT
SMALLINT
SET
,
SET('one', 'two')
NOT NULL
“''one ''two ''one,两
SET
SET
SET
SET
SET
MySQL的> SELECT
set_col
+0 FROMtbl_name
;
SET
SET | ||
---|---|---|
'a' | 1 | 0001 |
'b' | 2 | 0010 |
'c' | 4 | 0100 |
'd' | 8 | 1000 |
9
SET
'd'
SET
mysql> CREATE TABLE myset (col SET('a', 'b', 'c', 'd'));
'a,d'
'a,d,d'
'd,a,d'
MySQL的> INSERT INTO myset (col) VALUES
->(A,D),(想,'),(A,D,A),(A,D,D),(会,A,D);查询行,5行受影响(0.01秒)记录:5份:0警告:0
'a,d'
MySQL的> SELECT col FROM myset;
------ | Col | ------ | A、D | | A、D | | A、D | | A、D | | A、D | ------ 5行集(0.04秒)
SET
MySQL的> INSERT INTO myset (col) VALUES ('a,d,d,s');
查询行,1行的影响,1报警(0.03秒)MySQL > SHOW WARNINGS;
--------- ------ ------------------------------------------ |水平|代码|消息| --------- ------ ------------------------------------------ |警告| 1265 |数据截断柱Col在连续1 | --------- ------ ------------------------------------------ 1行集(0.04秒)MySQL > SELECT col FROM myset;
------ | Col | ------ | A、D | | A、D | | A、D | | A、D | | A、D | | A、D | ------ 6行集(0.01秒)
SET
SET
NULL
SUM()
AVG()
SET
FIND_IN_SET()
LIKE
MySQL的> SELECT * FROM
tbl_name
WHERE FIND_IN_SET('value
',set_col
)>0;MySQL的> SELECT * FROM
tbl_name
WHEREset_col
LIKE '%value
%';
set_col
value
set_col
value
mysql>SELECT * FROM
mysql>tbl_name
WHEREset_col
& 1;SELECT * FROM
tbl_name
WHEREset_col
= 'val1
,val2
';
'
val1
,val2
'val2
val1
SET
tbl_name
set_col
Type
SET
MyISAM
InnoDB
ARCHIVE
InnoDB
SPATIAL
GEOMETRY
POINT
LINESTRING
POLYGON
GEOMETRY
LINESTRING
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
GEOMETRYCOLLECTION
GEOMETRYCOLLECTION
MULTILINESTRING
GEOMETRYCOLLECTION
geom
CREATE TABLE geom (g GEOMETRY);
SPATIAL
NOT NULL
create table(G槽几何尺寸空);
SRID
创建表空间(P点不空SRID 0,几何不空SRID 4326);
InnoDB
MyISAM
SRID
SPATIAL
SRID
SRID
Geometry
Point
Curve
LineString
Line
LinearRing
Surface
Polygon
GeometryCollection
MultiPoint
MultiCurve
MultiLineString
MultiSurface
MultiPolygon
Geometry
Geometry
Curve
GeometryCollection
Point
Curve
Line
Surface
GeometryCollection
MultiLineString
Points
Polygons
MultiSurface
Surfaces
Geometry
Surface
MultiSurface
Point
Polygon
MultiPoint
MultiPolygon
Geometry
((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
LineString
MultiLineString
LineString
NULL
Point
Polygon
MultiLineString
Point
Point
Point
Point
Point
Point
Point
Curve
Curve
Curve
Curve
Curve
Curve
Curve
Curve
Curve
Curve
LineString
LineString
LineString
LineString
LineString
LineString
LineString
LineString
Surface
Surface
Surface
Surface
Surface
Polygon
Polygon
Polygon
Polygon
Polygon
Polygon
LineString
Polygon
Point
Polygon
Polygon
Polygon
Polygon
GeomCollection
GeomCollection
GeomCollection
GeomCollection
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiPoint
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiCurve
MultiLineString
LineString
MultiLineString
MultiLineString
MultiSurface
MultiPolygon
MultiSurface
MultiSurface
MultiSurface
MultiPolygon
Polygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
MultiPolygon
Polygon
Curve
Polygon
Curve
MultiPolygon
Point
(15分)
Point()
ST_X()
Point()
ST_GeomFromText()
MySQL的> SELECT ST_X(Point(15, 20));
| ST _ ------------------------ X(点(15,20)| ------------------------ |>15 | ------------------------ MySQL SELECT ST_X(ST_GeomFromText('POINT(15 20)'));
| --------------------------------------- _ X(ST ST _ geomfromtext(点(15)15)| --------------------------------------- | | ---------------------------------------
LineString
线(0 0,10 10,20 25,50 60)
Polygon
多贡((0 010 010 10人10,0 0 0 0 0),(5 5.7 5.7 7.5 7,5 5))
MultiPoint
MULTIPOINT(0 0, 20 20, 60 60)
ST_MPointFromText()
ST_GeomFromText()
ST_MPointFromText('MULTIPOINT (1 1, 2 2, 3 3)') ST_MPointFromText('MULTIPOINT ((1 1), (2 2), (3 3))')
MultiLineString
MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
MultiPolygon
MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
GeometryCollection
LineString
geometrycollection(点,点(10)(30),linestring(15,20))
BLOB
POINT(1
-1)
0101000000000000000000f03f000000000000f0bf
Point
Polygon
MultiLineString
GeometryCollection
Point
Point
Polygon
MultiLineString
GeometryCollection
GeometryCollection
LENGTH()
MySQL的> SET @g = ST_GeomFromText('POINT(1 -1)');
MySQL的> SELECT LENGTH(@g);
------------ |长度(@ G)| ------------ | 25 | ------------ MySQL > SELECT HEX(@g);
---------------------------------------------------- |十六进制(@(G)| ---------------------------------------------------- | 101000000000000000000f03f000000000000f0bf | ---------------------------------------------------- 000000000
1 byte for integer byte order (1 = little-endian)
4 bytes for integer type information (1 =Point
GeometryCollection
ST_IsValid()
mysql.st_spatial_reference_systems
ST_SPATIAL_REFERENCE_SYSTEMS
mysql>SELECT *
FROM INFORMATION_SCHEMA.ST_SPATIAL_REFERENCE_SYSTEMS
WHERE SRS_ID = 4326\G
*************************** 1. row *************************** SRS_NAME: WGS 84 SRS_ID: 4326 ORGANIZATION: EPSG ORGANIZATION_COORDSYS_ID: 4326 DEFINITION: GEOGCS["WGS 84",DATUM["World Geodetic System 1984", SPHEROID["WGS 84",6378137,298.257223563, AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]], UNIT["degree",0.017453292519943278, AUTHORITY["EPSG","9122"]], AXIS["Lat",NORTH],AXIS["Long",EAST], AUTHORITY["EPSG","4326"]] DESCRIPTION:
SRS_NAME
DEFINITION
SRS_ID
CREATE SPATIAL REFERENCE
SYSTEM
CREATE
TABLE
ALTER TABLE
MyISAM
InnoDB
NDB
ARCHIVE
CREATE TABLE
create table(G的几何尺寸);
ALTER TABLE
修改表的几何加PT点;改变表几何滴PT;
SET @g = 'LINESTRING(0 0,1 1,2 2)'; INSERT INTO geom VALUES (ST_GeomFromText(@g)); SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))'; INSERT INTO geom VALUES (ST_GeomFromText(@g)); SET @g = 'GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))'; INSERT INTO geom VALUES (ST_GeomFromText(@g));
ST_GeomFromText()
SET @g = 'POINT(1 1)';INSERT INTO geom VALUES (ST_PointFromText(@g));SET @g = 'LINESTRING(0 0,1 1,2 2)';INSERT INTO geom VALUES (ST_LineStringFromText(@g));SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';INSERT INTO geom VALUES (ST_PolygonFromText(@g));SET @g ='GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))';INSERT INTO geom VALUES (ST_GeomCollFromText(@g));
POINT(1 1)
插入到一个值(ST _ geomfromwkb(X 0101000000000000000000f03f000000000000f03f);
BLOB
插入一个值(st_geomfromwkb(?))
mysql_real_escape_string_quote()
CREATE TABLE geom2 (g GEOMETRY) SELECT g FROM geom;
ST_AsText()
选择st_astext(G)从几何;
ST_AsBinary()
BLOB
选择st_asbinary(G)从几何;
MyISAM
SPATIAL
SPATIAL
SPATIAL
MyISAM
SPATIAL
SPATIAL
InnoDB
SPATIAL
create table(G槽几何尺寸的空的空间指数(G));
创建表的几何(几何不为空);改变表几何添加空间索引(G);
create table(G槽几何尺寸空);创建在线空间几何指数G(g);
SPATIAL INDEX
ALTER
TABLE
DROP INDEX
修改表的几何下降指数G;
降G指数对几何;
geom
GEOMETRY
fid
MySQL的> DESCRIBE geom;
------- ---------- ------ ----- --------- ---------------- |场|型|空|关键|默认|额外| ------- ---------- ------ ----- --------- ---------------- | FID | int(11)| | PRI |空| auto_increment | | G |几何| | | | | ------- ---------- ------ ----- --------- ---------------- 2行集(0.001秒)MySQL > SELECT COUNT(*) FROM geom;
---------- |计数(*)| ---------- | 32376 | ---------- 1行集(0秒)
g
MySQL的> ALTER TABLE geom ADD SPATIAL INDEX(g);
查询行,32376行受影响(4.05秒)记录:32376份:0警告:0
MBRContains()
MBRWithin()
mysql>SET @poly =
->'Polygon((30000 15000, 31000 15000, 31000 16000, 30000 16000, 30000 15000))';
mysql>SELECT fid,ST_AsText(g) FROM geom WHERE
->MBRContains(ST_GeomFromText(@poly),g);
+-----+---------------------------------------------------------------+ | fid | ST_AsText(g) | +-----+---------------------------------------------------------------+ | 21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30 ... | | 22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8, ... | | 23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4, ... | | 24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4, ... | | 25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882. ... | | 26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4, ... | | 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946. ... | | 1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136. ... | | 2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136, ... | | 3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,3016 ... | | 4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30 ... | | 5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4, ... | | 6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,3024 ... | | 7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8, ... | | 10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6, ... | | 11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2, ... | | 13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,3011 ... | | 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30 ... | | 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30 ... | | 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4, ... | +-----+---------------------------------------------------------------+ 20 rows in set (0.00 sec)
EXPLAIN
MySQL的> SET @poly =
-> 'Polygon((30000 15000, 31000 15000, 31000 16000, 30000 16000, 30000 15000))';
MySQL的> EXPLAIN SELECT fid,ST_AsText(g) FROM geom WHERE
-> MBRContains(ST_GeomFromText(@poly),g)\G
*************************** 1。行***************************编号:1 select_type:简单表:几何类型:rangepossible_keys:G键:G key_len:32编号:空50行:额外的:用其中1行集(0秒)
mysql>SET @poly =
->'Polygon((30000 15000, 31000 15000, 31000 16000, 30000 16000, 30000 15000))';
mysql>EXPLAIN SELECT fid,ST_AsText(g) FROM g IGNORE INDEX (g) WHERE
->MBRContains(ST_GeomFromText(@poly),g)\G
*************************** 1. row *************************** id: 1 select_type: SIMPLE table: geom type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 32376 Extra: Using where 1 row in set (0.00 sec)
SELECT
MySQL的> SET @poly =
-> 'Polygon((30000 15000, 31000 15000, 31000 16000, 30000 16000, 30000 15000))';
MySQL的> SELECT fid,ST_AsText(g) FROM geom IGNORE INDEX (g) WHERE
-> MBRContains(ST_GeomFromText(@poly),g);
----- --------------------------------------------------------------- | FID | st_astext(G)| ----- --------------------------------------------------------------- | 1 |线(30250.4 15129.230248.8 15138.430238.2 15136。…| | 2 |线(30220.2 15122.830217.2 15137.830207.6 15136,…| | 3 |线(30179 15114.430176.6 15129.430167 151283016…| | 4 |线(30155.2 15121.430140.4 15118.630142 15109,30…| | 5 |线(30192.4 1508530177.6 15082.230179.2 15072.4,…| | 6 |线(30244 1508730229 15086.230229.4 15076.43024…| | 7 |线(30200.6 15059.430185.6 15058.630186 15048.8,…| | 10 |线(30179.6 15017.830181 15002.830190.8 15003.6,…| | 11 |线(30154.2 15000.430168.6 15004.830166 15014.2,…| | 13 |线(30105 15065.830108.4 15050.830118 150533011…| | 21 |线(30350.4 15828.830350.6 1584530333.8 15845,30…| | 22 |线(30350.6 15871.430350.6 15887.830334 15887.8,…| | 23 |线(30350.6 15914.230350.6 15930.430334 15930.4,…| | 24 |线(30290.2 1582330290.2 15839.430273.4 15839.4,…| | 25 |线(30291.4 15866.230291.6 15882.430274.8 15882。…| | 26 |线(30291.6 15918.230291.6 15934.430275 15934.4,…| | 154 |线(30276.2 15143.830261.4 1514130263 15131.4,30…| | 155 |线(30269.8 1508430269.4 15093.430258.6 15093,30…| | 157 |线(30128.2 1501130113.2 15010.230113.6 15000.4,…| | 249 |线(30337.8 15938.630337.8 15946.830320.4 15946。…| ----- --------------------------------------------------------------- 20行集(0.46秒)
JSON
JSON
JSON
JSON
JSON_MERGE_PATCH()
JSON
JSON
LONGBLOB
LONGTEXT
JSON
max_allowed_packet
JSON_STORAGE_SIZE()
JSON
JSON
JSON
JSON
JSON
JSON
UPDATE
JSON_SET()
JSON_REPLACE()
JSON_REMOVE()
UPDATE mytable SET jcol = '{"a": 10, "b": 25'}
JSON
UPDATE mytable SET jcol1
= JSON_SET(jcol2, '$.a', 100)
JSON_STORAGE_FREE()
binlog_row_value_options
[
["abc", 10, null, true, false]
{
{"k1": "value", "k2": 10}
["12:18:29.000000", "2015-07-29", "2015-07-29 12:18:29.000000"]
[99, {"id": "HK500", "cost": 75.99}, ["hot", "cold"]] {"k1": "value", "k2": [10, 20]}
JSON
CAST(
value
AS
JSON)
JSON
json_doc
json_val
JSON
MySQL的> CREATE TABLE t1 (jdoc JSON);
查询行,0行受影响(0.20秒)MySQL > INSERT INTO t1 VALUES('{"key1": "value1", "key2": "value2"}');
查询行,1行的影响(0.01秒)MySQL > INSERT INTO t1 VALUES('[1, 2,');
错误3140(22032)2行:无效的JSON文本:“无效值。”在价值6的位置(或列)”[ 1,2,”。
N
JSON_TYPE()
MySQL的> SELECT JSON_TYPE('["a", "b", 1]');
| ---------------------------- JSON _型([“A”,“B”,1 ])| ---------------------------- |阵列| MySQL > ---------------------------- SELECT JSON_TYPE('"hello"');
| ---------------------- JSON _型(“你好”)| ---------------------- |字符串> | ---------------------- MySQL SELECT JSON_TYPE('hello');
错误3146(22032):在争论1to功能json_type JSON数据的数据类型无效;JSON字符串或JSON类型是必需的。
utf8mb4
utf8mb4
utf8
utf8
JSON_ARRAY()
MySQL的> SELECT JSON_ARRAY('a', 1, NOW());
_ ---------------------------------------- | JSON数组(“A”,(1),现在| ---------------------------------------- |)[“”,1,“2015年7月27日09:43:| ---------------------------------------- 47.000000”]
JSON_OBJECT()
MySQL的> SELECT JSON_OBJECT('key1', 1, 'key2', 'abc');
_ --------------------------------------- | JSON对象(1 key2 KEY1是,是,是,是| --------------------------------------- |(ABC)“1”key2 KEY1,“:”:“ABC”} | ---------------------------------------
JSON_MERGE_PRESERVE()
MySQL的> SELECT JSON_MERGE_PRESERVE('["a", 1]', '{"key": "value"}');
----------------------------------------------------- | json_merge_preserve(“[”“]”,1,“{“钥匙”:“价值”}”)| ----------------------------------------------------- | [“一”,1,{“钥匙”:“价值”} ] | ----------------------------------------------------- 1行集(0秒)
JSON_MERGE_PATCH()
mysql>SET @j = JSON_OBJECT('key', 'value');
mysql>SELECT @j;
+------------------+ | @j | +------------------+ | {"key": "value"} | +------------------+
JSON
JSON
JSON_OBJECT()
utf8mb4
mysql> SELECT CHARSET(@j), COLLATION(@j);
+-------------+---------------+
| CHARSET(@j) | COLLATION(@j) |
+-------------+---------------+
| utf8mb4 | utf8mb4_bin |
+-------------+---------------+
utf8mb4_bin
MySQL的> SELECT JSON_ARRAY('x') = JSON_ARRAY('X');
+-----------------------------------+| JSON_ARRAY('x') = JSON_ARRAY('X') |+-----------------------------------+| 0 |+-----------------------------------+
null
false
MySQL的> SELECT JSON_VALID('null'), JSON_VALID('Null'), JSON_VALID('NULL');
—————————————————————————————————————— SELECT CAST('null' AS JSON);
---------------------- |铸('null作为JSON)| ---------------------- |空| ---------------------- 1行集(0秒)MySQL > SELECT CAST('NULL' AS JSON);
错误3141(22032):无效的JSON文本参数1功能cast_as_json:“无效值。”在0位“空”。
NULL
FALSE
MySQL的> SELECT ISNULL(null), ISNULL(Null), ISNULL(NULL);
isnull -------------- -------------- -------------- |(null)| isnull(null(空)| isnull)| -------------- -------------- -------------- | | | 1 1 1 | -------------- -------------- --------------
"
mysql> CREATE TABLE facts (sentence JSON);
mascot: The MySQL mascot is a dolphin named "Sakila".
facts
JSON_OBJECT()
MySQL的> INSERT INTO facts VALUES
> (JSON_OBJECT("mascot", "Our mascot is a dolphin named \"Sakila\"."));
mysql>INSERT INTO facts VALUES
>('{"mascot": "Our mascot is a dolphin named \\"Sakila\\"."}');
SELECT
MySQL的> SELECT sentence FROM facts;
--------------------------------------------------------- |句| --------------------------------------------------------- | {“吉祥物”:“我们的吉祥物是一只海豚命名为“sakila \“。”} | ---------------------------------------------------------
mascot
->
mysql> SELECT col->"$.mascot" FROM qtest;+---------------------------------------------+| col->"$.mascot" |+---------------------------------------------+| "Our mascot is a dolphin named \"Sakila\"." |+---------------------------------------------+1 row in set (0.00 sec)
mascot
->>
MySQL的> SELECT sentence->>"$.mascot" FROM facts;
+-----------------------------------------+| sentence->>"$.mascot" |+-----------------------------------------+| Our mascot is a dolphin named "Sakila". |+-----------------------------------------+
NO_BACKSLASH_ESCAPES
mysql>INSERT INTO facts VALUES
>(JSON_OBJECT('mascot', 'Our mascot is a dolphin named "Sakila".'));
JSON_UNQUOTE()
JSON_OBJECT()
mysql> SELECT JSON_OBJECT('key1', 1, 'key2', 'abc', 'key1', 'def');
+------------------------------------------------------+
| JSON_OBJECT('key1', 1, 'key2', 'abc', 'key1', 'def') |
+------------------------------------------------------+
| {"key1": "def", "key2": "abc"} |
+------------------------------------------------------+
mysql>CREATE TABLE t1 (c1 JSON);
mysql>INSERT INTO t1 VALUES
>('{"x": 17, "x": "red"}'),
>('{"x": 17, "x": "red", "x": [3, 5, 7]}');
mysql>SELECT c1 FROM t1;
+------------------+ | c1 | +------------------+ | {"x": "red"} | | {"x": [3, 5, 7]} | +------------------+
JSON_OBJECT()
mysql> SELECT JSON_OBJECT('key1', 1, 'key2', 'abc', 'key1', 'def');
+------------------------------------------------------+
| JSON_OBJECT('key1', 1, 'key2', 'abc', 'key1', 'def') |
+------------------------------------------------------+
| {"key1": 1, "key2": "abc"} |
+------------------------------------------------------+
mysql>CREATE TABLE t1 (c1 JSON);
mysql>INSERT INTO t1 VALUES
>('{"x": 17, "x": "red"}'),
>('{"x": 17, "x": "red", "x": [3, 5, 7]}');
mysql>SELECT c1 FROM t1;
+-----------+ | c1 | +-----------+ | {"x": 17} | | {"x": 17} | +-----------+
JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH()
JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH()
JSON_MERGE_PRESERVE()
JSON_MERGE()
JSON_MERGE_PRESERVE()
mysql>SELECT
->JSON_MERGE_PRESERVE('[1, 2]', '["a", "b", "c"]', '[true, false]') AS Preserve,
->JSON_MERGE_PATCH('[1, 2]', '["a", "b", "c"]', '[true, false]') AS Patch\G
*************************** 1. row *************************** Preserve: [1, 2, "a", "b", "c", true, false] Patch: [true, false]
JSON_MERGE_PRESERVE()
a
MySQL的> SELECT
-> JSON_MERGE_PRESERVE('{"a": 1, "b": 2}', '{"c": 3, "a": 4}', '{"c": 5, "d": 3}') AS Preserve,
-> JSON_MERGE_PATCH('{"a": 3, "b": 2}', '{"c": 3, "a": 4}', '{"c": 5, "d": 3}') AS Patch\G
*************************** 1。行***************************保存:{“”:[ 1,4 ],“B”:2,“C”:[ 3,5 ],“D”:3 }补丁:{“”:4,“B”:2,“C”:5,“D”:3 }
[
[1]
JSON_MERGE_PRESERVE()
mysql>SELECT
->JSON_MERGE_PRESERVE('1', '2') AS Preserve,
->JSON_MERGE_PATCH('1', '2') AS Patch\G
*************************** 1. row *************************** Preserve: [1, 2] Patch: 2
JSON_MERGE_PRESERVE()
mysql>SELECT
->JSON_MERGE_PRESERVE('[10, 20]', '{"a": "x", "b": "y"}') AS Preserve,
->JSON_MERGE_PATCH('[10, 20]', '{"a": "x", "b": "y"}') AS Patch\G
*************************** 1. row *************************** Preserve: [10, 20, {"a": "x", "b": "y"}] Patch: {"a": "x", "b": "y"}
name
MySQL的> SELECT JSON_EXTRACT('{"id": 14, "name": "Aztalan"}', '$.name');
--------------------------------------------------------- | json _提取物(“{“id”:14,“名字”:“aztalan“}”,“美元”.name)| --------------------------------------------------------- |”aztalan”| ---------------------------------------------------------
$
[
N
]path
N
path
path
path
MySQL的> SELECT JSON_SET('"x"', '$[0]', 'a');
------------------------------ | JSON _集(“X”,〔0〕美元,在| ------------------------------ |)”到“| ------------------------------ 1行集(0秒)
[
M
to
N
]M
N
last
path
path
path
*
.[*]
[*]
prefix
**suffix
NULL
$
[ 3,{“”:[ 5, 6 ],“B”:10 },[ 99, 100 ] ]
$[0]
$[1]
$[2]
$[3]
$[1]
$[1].a
$[1].a[1]
$[1].b
$[2][0]
$
{“鱼”:“鲨鱼”,“鸟”:“麻雀”}
$."a fish"
$."a bird"
mysql>SELECT JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.*');
+---------------------------------------------------------+ | JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.*') | +---------------------------------------------------------+ | [1, 2, [3, 4, 5]] | +---------------------------------------------------------+ mysql>SELECT JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.c[*]');
+------------------------------------------------------------+ | JSON_EXTRACT('{"a": 1, "b": 2, "c": [3, 4, 5]}', '$.c[*]') | +------------------------------------------------------------+ | [3, 4, 5] | +------------------------------------------------------------+
$**.b
$.c.b
MySQL的> SELECT JSON_EXTRACT('{"a": {"b": 1}, "c": {"b": 2}}', '$**.b');
* * * * * * * * * * * * * * * *
to
mysql> SELECT JSON_EXTRACT('[1, 2, 3, 4, 5]', '$[1 to 3]');
+----------------------------------------------+
| JSON_EXTRACT('[1, 2, 3, 4, 5]', '$[1 to 3]') |
+----------------------------------------------+
| [2, 3, 4] |
+----------------------------------------------+
1 row in set (0.00 sec)
M
to
N
M
N
N
M
M
last
N
MySQL的> SELECT JSON_EXTRACT('[1, 2, 3, 4, 5]', '$[last-3 to last-1]');
-------------------------------------------------------- | json_extract(' [ 1,2,3,4,5 ],[ last-3美元来last-1 ]”)| -------------------------------------------------------- | [ 2,3,4 ] | -------------------------------------------------------- 1行集(0.01秒)
mysql> SELECT JSON_REPLACE('"Sakila"', '$[last]', 10); +-----------------------------------------+ | JSON_REPLACE('"Sakila"', '$[last]', 10) | +-----------------------------------------+ | 10 | +-----------------------------------------+ 1 row in set (0.00 sec)
column
->path
JSON_EXTRACT(
column
,
path
)
JSON_SET()
JSON_INSERT()
JSON_REPLACE()
mysql> SET @j = '["a", {"b": [true, false]}, [10, 20]]';
JSON_SET()
MySQL的> SELECT JSON_SET(@j, '$[1].b[0]', 1, '$[2][2]', 2);
-------------------------------------------- | JSON _集(@美元〔1〕J〕.b〔0,1,2〔2〕〔元〕,〔2 | -------------------------------------------- |)“A”,“B”:{ } [假] [ 1,2,10,20,| -------------------------------------------- ]
$[1].b[0]
1
2
JSON_INSERT()
MySQL的> SELECT JSON_INSERT(@j, '$[1].b[0]', 1, '$[2][2]', 2);
----------------------------------------------- | JSON _ insert(@美元〔1〕J〕.b〔0,1,2〔2〕〔元〕,〔2 | ----------------------------------------------- |)“A”,“B”:{ } [假],[真正的,10,20,2 | ----------------------------------------------- ]
JSON_REPLACE()
MySQL的> SELECT JSON_REPLACE(@j, '$[1].b[0]', 1, '$[2][2]', 2);
------------------------------------------------ | JSON _ replace(@美元〔1〕J〕.b〔0,1,2〔2〕〔元〕,〔2 | ------------------------------------------------ |)“A”,“B”:{ } [ 1 ],[假],10,20 | ------------------------------------------------
JSON_REMOVE()
MySQL的> SELECT JSON_REMOVE(@j, '$[2]', '$[1].b[1]', '$[1].b[1]');
--------------------------------------------------- | JSON _ remove(@美元J,[ 2 ],[ 1 ] .b美元美元〔1〕,〔1〕〔1〕.b)| --------------------------------------------------- | [“A”,“B”:{ } [真] | --------------------------------------------------- ]
$[2]
$[1].b[1]
b
$[1].b[1]
=
<
<=
>
>=
<>
!=
<=>
JSON_TYPE()
blobbitopaquedatetimetimedatebooleanarrayobjectstringinteger,doublenull
BLOB
N
N
N
BIT
BLOB
OPAQUE
BLOB
DATETIME
DATETIME
TIME
DATE
ARRAY
[] < ["a"] < ["ab"] < ["ab", "cd", "ef"] < ["ab", "ef"]
BOOLEAN
OBJECT
{"a": 1, "b": 2} = {"b": 2, "a": 1}
STRING
N
N
N
"a" < "ab" < "b" < "bc"
utf8mb4_bin
"A" < "a"
INTEGER
INT
DOUBLE
9223372036854775805 < 9223372036854775806 < 9223372036854775807 < 9.223372036854776e18 = 9223372036854776000 < 9223372036854776001
9223372036854775805 < 9223372036854775806 < 9223372036854775807
9223372036854775805 = 9223372036854775806 = 9223372036854775807 = 9.223372036854776e18
NULL
utf8mb4
ascii | utf8mb4 | |
utf8mb4 | utf8mb4 | |
NULL | NULL | |
ST_AsGeoJSON() | CAST( ST_GeomFromGeoJSON() | |
NULL |
ORDER BY
NULL
max_sort_length
max_sort_length
jdoc
id
以铸造(json_extract(JDoc,“美元。ID)为无符号)
ORDER BY
NULL
MIN()
MAX()
GROUP_CONCAT()
DEFAULT
value
创建表T1(我int默认1,C varchar(10)违约”,价格翻番(16)默认为0);
SERIAL DEFAULT VALUE
DEFAULT
DEFAULT
创建表T1(--文字默认我int默认0,C varchar(10)默认”--表达默认F浮默认(rand() * rand()),B(16)二进制默认(uuid_to_bin(uuid()))、D(current_date日期默认间隔1年),P点的默认(点(0,0)),J JSON默认(json_array()));
TIMESTAMP
DATETIME
CURRENT_TIMESTAMP
BLOB
TEXT
JSON
CREATE TABLE t2 (b BLOB DEFAULT ('abc'));
CREATE TABLE t2 (b BLOB DEFAULT 'abc');
AUTO_INCREMENT
ALTER TABLE
CREATE
TABLE ... LIKE
CREATE
TABLE ... SELECT
INSERT
UPDATE
ALTER TABLE
DEFAULT
MySQL的> CREATE TABLE t4 (uid BINARY(16) DEFAULT (UUID_TO_BIN(UUID())));
MySQL的> INSERT INTO t4 () VALUES();
MySQL的> INSERT INTO t4 () VALUES(DEFAULT);
MySQL的> SELECT BIN_TO_UUID(uid) AS uid FROM t4;
-------------------------------------- | UID | -------------------------------------- | f1109174 - 94c9 - 11e8 - 971d - 3bf1095aa633 | | f110cf9a - 94c9 - 11e8 - 971d - 3bf1095aa633 | --------------------------------------
DEFAULT(
col_name
)
ER_UNSUPPORTED_ACTION_ON_DEFAULT_VAL_GENERATED
DEFAULT
NOW()
CURRENT_DATE
TIMESTAMP
DATETIME
CURRENT_TIMESTAMP
BLOB
TEXT
JSON
DEFAULT
NULL
NULL
PRIMARY KEY
NOT NULL
NOT NULL
NOT NULL
INSERT
REPLACE
UPDATE
t
创建表的T(I型不为空);
i
DEFAULT(i)
插入T values();插入T值(默认);插入T值(默认(我));
SHOW CREATE
TABLE
0
TIMESTAMP
TIMESTAMP
explicit_defaults_for_timestamp
TIMESTAMP
BLOB
TEXT
BLOB
TEXT
TINYINT | |
SMALLINT | |
MEDIUMINT | |
INT INTEGER | |
BIGINT | |
FLOAT( | 4 bytes if 0 <=p <= 24, 8 bytes if 25 <=p <= 53 |
FLOAT | |
DOUBLE [PRECISION] REAL | |
DECIMAL(
| |
BIT( | M |
DECIMAL
NUMERIC
TIME
DATETIME
TIMESTAMP
YEAR | ||
DATE | ||
TIME | ||
DATETIME | ||
TIMESTAMP |
YEAR
DATE
TIME
DATETIME
TIMESTAMP
DATETIME
TIME(0)
TIME(2)
TIME(4)
TIME(6)
TIME
TIME(0)
M
L
CHAR( | M w <= w |
BINARY( | M <= |
VARCHAR(
| L L |
TINYBLOB TINYTEXT | L L < 2 |
BLOB TEXT | L L < 2 |
MEDIUMBLOB MEDIUMTEXT | L L < 2 |
LONGBLOB LONGTEXT | L L < 2 |
ENUM(' | |
SET(' |
L
MEDIUMTEXT
L
CHAR
VARCHAR
TEXT
utf8mb3
utf8mb3
VARCHAR
VARBINARY
BLOB
TEXT
VARCHAR(255)
L
L
'abcd'
VARCHAR
VARBINARY
VARCHAR
utf8mb4
VARCHAR
InnoDB
utf8mb4
ENUM
SET
N
N
SET
JSON
LONGTEXT
JSON
max_allowed_packet
1
MEDIUMINT UNSIGNED
+
*
DECIMAL
DOUBLE
BIGINT
BOOL | TINYINT |
BOOLEAN | TINYINT |
CHARACTER VARYING( | VARCHAR( |
FIXED | DECIMAL |
FLOAT4 | FLOAT |
FLOAT8 | DOUBLE |
INT1 | TINYINT |
INT2 | SMALLINT |
INT3 | MEDIUMINT |
INT4 | INT |
INT8 | BIGINT |
LONG VARBINARY | MEDIUMBLOB |
LONG VARCHAR | MEDIUMTEXT |
LONG | MEDIUMTEXT |
MIDDLEINT | MEDIUMINT |
NUMERIC | DECIMAL |
DESCRIBE
tbl_name
MySQL的> CREATE TABLE t (a BOOL, b FLOAT8, c LONG VARCHAR, d NUMERIC);
查询行,0行受影响(0秒)MySQL > DESCRIBE t;
------- --------------- ------ ----- --------- ------- |场|型|空|关键|默认|额外| ------- --------------- ------ ----- --------- ------- |一| tinyint(1)|是| |空| | | B |双|是| |空| | | C | mediumtext |是| |空| | | D |十进制(10,0)|是| |空| | ------- --------------- ------ ----- --------- ------- 4行集(0.01秒)