ORDER BY
SELECT
SELECT
DELETE
UPDATE
SET
NULL
--sql-mode=IGNORE_SPACE
CLIENT_IGNORE_SPACE
mysql_real_connect()
mysql> SELECT MOD(29,9);
+-----------+
| mod(29,9) |
+-----------+
| 2 |
+-----------+
1 rows in set (0.00 sec)
mysql> SELECT MOD(29,9);
-> 2
mysql>SELECT 1+'1';
-> 2 mysql>SELECT CONCAT(2,' test');
-> '2 test'
CAST()
CONCAT()
MySQL的> SELECT 38.8, CAST(38.8 AS CHAR);
-> 38.8, '38.8'mysql>SELECT 38.8, CONCAT(38.8);
> 38.8、38.8
CREATE TABLE ... SELECT
NULL
NULL
<=>
NULL <=> NULL
TIMESTAMP
DATETIME
IN()
BETWEEN
CAST()
DATETIME
DATETIME
CAST()
DATETIME
mysql>SELECT 1 > '6x';
-> 0 mysql>SELECT 7 > '6x';
-> 1 mysql>SELECT 0 > 'x6';
-> 0 mysql>SELECT 0 = 'x6';
-> 1
str_col
SELECT * FROM tbl_name
哪里 str_col
=1;
1
' 1'
mysql>SELECT '18015376320243458' = 18015376320243458;
-> 1 mysql>SELECT '18015376320243459' = 18015376320243459;
-> 0
mysql> SELECT '18015376320243459'+0.0;
-> 1.8015376320243e+16
CAST()
MySQL的> SELECT CAST('18015376320243459' AS UNSIGNED) = 18015376320243459;
-> 1
dtoa
DECIMAL
FLOAT
DOUBLE
dtoa
dtoa
dtoa
D
DECIMAL
F
F
D
D
F
D
F
F
D
F
D
F
F
+inf
FLOAT
DOUBLE
D
F
D
D
+inf
D
character_set_connection
collation_connection
SET NAMES
CHAR
VARCHAR
LONGTEXT
BINARY
VARBINARY
LONGBLOB
CREATE TABLE t SELECT integer_expr
;
INT
BIGINT
INT
BIGINT
SELECT
BIGINT
INT
create table SELECT 000000000000000000000吨;
AND
| |
= | SET
UPDATE |
:= | |
BETWEEN ... AND ... | |
BINARY | |
& | |
~ | |
| | |
^ | |
CASE | |
DIV | |
/ | |
= | |
<=> | |
> | |
>= | |
IS | |
IS NOT | |
IS NOT NULL | |
IS NULL | |
-> | |
->> | |
<< | |
< | |
<= | |
LIKE | |
- | |
%
| |
NOT
| |
NOT BETWEEN ... AND ... | |
!= <> | |
NOT LIKE | |
NOT REGEXP | |
||
| |
+ | |
REGEXP | |
>> | |
RLIKE | |
SOUNDS LIKE | |
* | |
- | |
XOR |
INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + <<, >> & | = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN BETWEEN, CASE, WHEN, THEN, ELSE NOT AND, && XOR OR, || = (assignment), :=
=
=
=
<=>
>=
>
<=
<
<>
!=
IS
LIKE
REGEXP
IN
:=
=
||
OR
PIPES_AS_CONCAT
||
^
!
HIGH_NOT_PRECEDENCE
!
mysql>SELECT 1+2*3;
-> 7 mysql>SELECT (1+2)*3;
-> 9
BETWEEN ... AND ... | |
COALESCE() | |
= | |
<=> | |
> | |
>= | |
GREATEST() | |
IN() | |
INTERVAL() | |
IS | |
IS NOT | |
IS NOT NULL | |
IS NULL | |
ISNULL() | |
LEAST() | |
< | |
<= | |
LIKE | |
NOT BETWEEN ... AND ... | |
!= <> | |
NOT IN() | |
NOT LIKE | |
STRCMP() |
1
0
NULL
= > < >= <= <> !=
1
0
NULL
LEAST()
GREATEST()
LEAST()
LEAST("11",
"45", "2")
LEAST("11", "45", "2") + 0
LEAST("11", "45", "2") +
0
CAST()
CONVERT()
utf8mb4
mysql>SELECT 1 = 0;
-> 0 mysql>SELECT '0' = 0;
-> 1 mysql>SELECT '0.0' = 0;
-> 1 mysql>SELECT '0.01' = 0;
-> 0 mysql>SELECT '.01' = 0.01;
-> 1
(a, b) = (x, y)
(a = x) AND (b = y)
NULL
=
NULL
0
NULL
<=>
mysql>SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
-> 1, 1, 0 mysql>SELECT 1 = 1, NULL = NULL, 1 = NULL;
-> 1, NULL, NULL
(a, b) <=> (x,
y)
(a <=> x) AND (b <=> y)
mysql>SELECT '.01' <> '0.01';
-> 1 mysql>SELECT .01 <> '0.01';
-> 0 mysql>SELECT 'zapp' <> 'zappp';
-> 1
(a, b) <> (x,
y)
(a, b) != (x, y)
(a <> x) OR (b <> y)
mysql> SELECT 0.1 <= 2;
-> 1
(a, b) <= (x, y)
(a < x) OR ((a = x) AND (b <= y))
mysql> SELECT 2 < 2;
-> 0
(a, b) < (x, y)
(a < x) OR ((a = x) AND (b < y))
mysql> SELECT 2 >= 2;
-> 1
(a, b) >= (x, y)
(a > x) OR ((a = x) AND (b >= y))
mysql> SELECT 2 > 2;
-> 0
(a, b) > (x, y)
(a > x) OR ((a = x) AND (b > y))
boolean_value
FALSE
mysql> SELECT 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN;
-> 1, 1, 1
boolean_value
FALSE
mysql> SELECT 1 IS NOT UNKNOWN, 0 IS NOT UNKNOWN, NULL IS NOT UNKNOWN;
-> 1, 1, 0
NULL
MySQL的> SELECT 1 IS NULL, 0 IS NULL, NULL IS NULL;
> 0, 0, 1
IS
NULL
sql_auto_is_null
SELECT * FROMtbl_name
WHEREauto_col
IS NULL
LAST_INSERT_ID()
AUTO_INCREMENT
SELECT
AUTO_INCREMENT
IS NULL
sql_auto_is_null = 0
sql_auto_is_null
DATE
DATETIME
'0000-00-00'
SELECT * FROM tbl_name
哪里 date_column
是空的
'0000-00-00'
FLAG_AUTO_IS_NULL
NULL
MySQL的> SELECT 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
> 1, 1, 0
expr
min
expr
max
BETWEEN
0
min
<=expr
expr
<=max
mysql>SELECT 2 BETWEEN 1 AND 3, 2 BETWEEN 3 and 1;
-> 1, 0 mysql>SELECT 1 BETWEEN 2 AND 3;
-> 0 mysql>SELECT 'b' BETWEEN 'a' AND 'c';
-> 1 mysql>SELECT 2 BETWEEN 2 AND '3';
-> 1 mysql>SELECT 2 BETWEEN 2 AND 'x-3';
-> 0
BETWEEN
CAST()
DATETIME
DATE
DATE
DATETIME
DATE
DATE
NOT
(
expr
BETWEEN
min
AND
max
)
NULL
NULL
COALESCE()
MySQL的> SELECT COALESCE(NULL,1);
-> 1mysql>SELECT COALESCE(NULL,NULL,NULL);
>0
LEAST()
MySQL的> SELECT GREATEST(2,0);
-> 2mysql>SELECT GREATEST(34.0,3.0,5.0,767.0);
-> 767.0mysql>SELECT GREATEST('B','A','C');
→C
GREATEST()
NULL
1
expr
0
expr
IN
mysql>SELECT 2 IN (0,3,5,7);
-> 0 mysql>SELECT 'wefwf' IN ('wee','wefwf','weg');
-> 1
IN
MySQL的> SELECT (3,4) IN ((1,2), (3,4));
-> 1mysql>SELECT (3,4) IN ((1,2), (3,5));
> 0
IN
SELECT val1 FROM tbl1 WHERE val1 IN (1,2,'a');
SELECT val1 FROM tbl1 WHERE val1 IN ('1','2','a');
IN
max_allowed_packet
IN
NULL
IN()
NOT
(
expr
IN
(value
,...))
expr
ISNULL()
0
MySQL的> SELECT ISNULL(1+1);
-> 0mysql>SELECT ISNULL(1/0);
-> 1
0
N
<N1
N
<N2
N
N1
<N2
<N3
<
<Nn
MySQL的> SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
-> 3mysql>SELECT INTERVAL(10, 1, 10, 100, 1000);
-> 2mysql>SELECT INTERVAL(22, 23, 30, 44, 200);
> 0
LEAST()
MySQL的> SELECT LEAST(2,0);
-> 0mysql>SELECT LEAST(34.0,3.0,5.0,767.0);
-> 3.0mysql>SELECT LEAST('B','A','C');
- >“A”
TRUE
NULL
TRUE
NULL
NULL
TRUE
MySQL的> SELECT 10 IS TRUE;
-> 1mysql>SELECT -10 IS TRUE;
-> 1mysql>SELECT 'string' IS NOT NULL;
-> 1
1
0
NULL
MySQL的> SELECT NOT 10;
-> 0mysql>SELECT NOT 0;
-> 1mysql>SELECT NOT NULL;
-> NULLmysql>SELECT ! (1+1);
-> 0mysql>SELECT ! 1+1;
-> 1
1
1
0
NULL
MySQL的> SELECT 1 AND 1;
-> 1mysql>SELECT 1 AND 0;
-> 0mysql>SELECT 1 AND NULL;
-> NULLmysql>SELECT 0 AND NULL;
-> 0mysql>SELECT NULL AND 0;
> 0
NULL
0
1
NULL
mysql>SELECT 1 OR 1;
-> 1 mysql>SELECT 1 OR 0;
-> 1 mysql>SELECT 0 OR 0;
-> 0 mysql>SELECT 0 OR NULL;
-> NULL mysql>SELECT 1 OR NULL;
-> 1
NULL
NULL
0
MySQL的> SELECT 1 XOR 1;
-> 0mysql>SELECT 1 XOR 0;
-> 1mysql>SELECT 1 XOR NULL;
-> NULLmysql>SELECT 1 XOR 1 XOR 1;
-> 1
a XOR b
SET
=
:=
:=
SET
MySQL的> SELECT @var1, @var2;
-> NULL, NULLmysql>SELECT @var1 := 1, @var2;
-> 1, NULLmysql>SELECT @var1, @var2;
-> 1, NULLmysql>SELECT @var1, @var2 := @var1;
-> 1, 1mysql>SELECT @var1, @var2;
-> 1, 1mysql>SELECT @var1:=COUNT(*) FROM t1;
-> 4mysql>SELECT @var1;
->四
:=
SELECT
UPDATE
MySQL的> SELECT @var1;
-> 4mysql>SELECT * FROM t1;
-> 1, 3, 5, 7mysql>UPDATE t1 SET c1 = 2 WHERE c1 = @var1:= 1;
查询行,1行的影响(0秒)的行匹配:1改变:1警告:0mysql > SELECT @var1;
-> 1mysql>SELECT * FROM t1;
> 2, 3, 5、7
:=
SET
=
SET
=
:=
SET
SET
UPDATE
=
WHERE
UPDATE
UPDATE
=
mysql>SELECT @var1, @var2;
-> NULL, NULL mysql>SELECT @var1 := 1, @var2;
-> 1, NULL mysql>SELECT @var1, @var2;
-> 1, NULL mysql>SELECT @var1, @var2 := @var1;
-> 1, 1 mysql>SELECT @var1, @var2;
-> 1, 1
CASE
value
WHEN
[compare_value
] THEN
result
[WHEN
[compare_value
] THEN
result
...] [ELSE
result
] END
CASE WHEN
[
condition
] THEN
result
[WHEN
[condition
] THEN
result
...] [ELSE
result
] END
CASE
result
value
=compare_value
NULL
CASE
CASE
CASE
END CASE
CASE
MySQL的> SELECT CASE 1 WHEN 1 THEN 'one'
-> WHEN 2 THEN 'two' ELSE 'more' END;
-> 'one'mysql>SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
-> 'true'mysql>SELECT CASE BINARY 'B'
-> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
>0
expr1
expr1
<>
0expr1
<> NULLIF()
expr2
expr3
IF
IF()
expr2
expr3
IF()
IF()
expr2
expr3
expr2
expr3
expr2
expr3
expr2
expr3
MySQL的> SELECT IF(1>2,2,3);
-> 3mysql>SELECT IF(1<2,'yes','no');
-> 'yes'mysql>SELECT IF(STRCMP('test','test1'),'no','yes');
→不
expr1
IFNULL()
expr1
expr2
MySQL的> SELECT IFNULL(1,0);
-> 1mysql>SELECT IFNULL(NULL,10);
-> 10mysql>SELECT IFNULL(1/0,10);
-> 10mysql>SELECT IFNULL(1/0,'yes');
- >“是”
IFNULL(
expr1
,expr2
)STRING
INTEGER
IFNULL()
MySQL的> CREATE TABLE tmp SELECT IFNULL(1,'test') AS test;
MySQL的> DESCRIBE tmp;
------- -------------- ------ ----- --------- ------- |场|型|空|关键|默认|额外| ------- -------------- ------ ----- --------- ------- |测试| varbinary(4)|没有| | | | ------- -------------- ------ ----- --------- -------
test
VARBINARY(4)
NULL
expr1
=expr2
expr1
CASE WHEN
expr1
=
expr2
THEN NULL ELSE
expr1
END
mysql>SELECT NULLIF(1,1);
-> NULL mysql>SELECT NULLIF(1,2);
-> 1
expr1
ASCII() | |
BIN() | |
BIT_LENGTH() | |
CHAR() | |
CHAR_LENGTH() | |
CHARACTER_LENGTH() | |
CONCAT() | |
CONCAT_WS() | |
ELT() | |
EXPORT_SET() | |
FIELD() | |
FIND_IN_SET() | |
FORMAT() | |
FROM_BASE64() | |
HEX() | |
INSERT() | |
INSTR() | |
LCASE() | |
LEFT() | |
LENGTH() | |
LIKE | |
LOAD_FILE() | |
LOCATE() | |
LOWER() | |
LPAD() | |
LTRIM() | |
MAKE_SET() | |
MATCH | |
MID() | |
NOT LIKE | |
NOT REGEXP | |
OCT() | |
OCTET_LENGTH() | |
ORD() | |
POSITION() | |
QUOTE() | |
REGEXP | |
REGEXP_INSTR() | |
REGEXP_LIKE() | |
REGEXP_REPLACE() | |
REGEXP_SUBSTR() | |
REPEAT() | |
REPLACE() | |
REVERSE() | |
RIGHT() | |
RLIKE | |
RPAD() | |
RTRIM() | |
SOUNDEX() | |
SOUNDS LIKE | |
SPACE() | |
STRCMP() | |
SUBSTR() | |
SUBSTRING() | |
SUBSTRING_INDEX() | |
TO_BASE64() | |
TRIM() | |
UCASE() | |
UNHEX() | |
UPPER() | |
WEIGHT_STRING() |
NULL
max_allowed_packet
str
str
str
ASCII()
MySQL的> SELECT ASCII('2');
-> 50mysql>SELECT ASCII(2);
-> 50mysql>SELECT ASCII('dx');
->百
ORD()
N
N
BIGINT
CONV(
N
,10,2)N
mysql> SELECT BIN(12);
-> '1100'
str
MySQL的> SELECT BIT_LENGTH('text');
> 32
CHAR(
N
,...
[USING charset_name
])
CHAR()
N
mysql>SELECT CHAR(77,121,83,81,'76');
-> 'MySQL' mysql>SELECT CHAR(77,77.3,'77.3');
-> 'MMM'
CHAR()
CHAR(256)
CHAR(1,0)
CHAR(256*256)
CHAR(1,0,0)
MySQL的> SELECT HEX(CHAR(1,0)), HEX(CHAR(256));
---------------- ---------------- |进制(char(1,0))|进制(char(256))| ---------------- ---------------- | 0100 | 0100 | ---------------- ---------------- MySQL > SELECT HEX(CHAR(1,0,0)), HEX(CHAR(256*256));
------------------ -------------------- |进制(char(1,0,0))|进制(char(256×256))| ------------------ -------------------- | 010000 | 010000 | ------------------ --------------------
CHAR()
mysql> SELECT CHARSET(CHAR(X'65')), CHARSET(CHAR(X'65' USING utf8));
+----------------------+---------------------------------+
| CHARSET(CHAR(X'65')) | CHARSET(CHAR(X'65' USING utf8)) |
+----------------------+---------------------------------+
| binary | utf8 |
+----------------------+---------------------------------+
USING
CHAR()
str
LENGTH()
CHAR_LENGTH()
CONCAT()
NULL
MySQL的> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'mysql>SELECT CONCAT('My', NULL, 'QL');
-> NULLmysql>SELECT CONCAT(14.3);
> 14.3
mysql> SELECT 'My' 'S' 'QL';
-> 'MySQL'
CONCAT_WS(
separator
,str1
,str2
,...)
CONCAT_WS()
CONCAT()
NULL
MySQL的> SELECT CONCAT_WS(',','First name','Second name','Last Name');
-> 'First name,Second name,Last Name'mysql>SELECT CONCAT_WS(',','First name',NULL,'Last Name');
- >“名字,姓氏”
CONCAT_WS()
ELT()
N
str1
N
=str2
N
=NULL
N
ELT()
FIELD()
MySQL的> SELECT ELT(1, 'Aa', 'Bb', 'Cc', 'Dd');
-> 'Aa'mysql>SELECT ELT(4, 'Aa', 'Bb', 'Cc', 'Dd');
-对不起
EXPORT_SET(
bits
,on
,off
[,separator
[,number_of_bits
]])
bits
on
off
bits
separator
number_of_bits
number_of_bits
MySQL的> SELECT EXPORT_SET(5,'Y','N',',',4);
-> 'Y,N,Y,N'mysql>SELECT EXPORT_SET(6,'1','0',',',10);
- >“0,1,1,0,0,0,0,0,0,0”
str
str1
str2
str3
0
str
FIELD()
str
0
FIELD()
ELT()
MySQL的> SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
-> 2mysql>SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
> 0
N
str
strlist
N
SET
FIND_IN_SET()
str
strlist
strlist
NULL
mysql> SELECT FIND_IN_SET('b','a,b,c,d');
-> 2
X
D
D
lc_time_names
'en_US'
MySQL的> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235'mysql>SELECT FORMAT(12332.1,4);
-> '12,332.1000'mysql>SELECT FORMAT(12332.2,0);
-> '12,332'mysql>SELECT FORMAT(12332.2,2,'de_DE');
- >“12.332,20”
TO_BASE64()
NULL
TO_BASE64()
MySQL的> SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc'));
我是ABC jwjj >,是
str
HEX()
str
str
UNHEX()
N
HEX()
N
BIGINT
CONV(
N
,10,16)CONV(HEX(
N
),16,10)
MySQL的> SELECT X'616263', HEX('abc'), UNHEX(HEX('abc'));
-> 'abc', 616263, 'abc'mysql>SELECT HEX(255), CONV(HEX(255),16,10);
→是FF,255
str
pos
len
newstr
pos
pos
len
NULL
MySQL的> SELECT INSERT('Quadratic', 3, 4, 'What');
-> 'QuWhattic'mysql>SELECT INSERT('Quadratic', -1, 4, 'What');
-> 'Quadratic'mysql>SELECT INSERT('Quadratic', 3, 100, 'What');
- >“quwhat”
substr
str
LOCATE()
MySQL的> SELECT INSTR('foobarbar', 'bar');
-> 4mysql>SELECT INSTR('xbar', 'foobar');
> 0
LCASE()
len
str
NULL
MySQL的> SELECT LEFT('foobarbar', 5);
fooba’->’
str
LENGTH()
CHAR_LENGTH()
mysql> SELECT LENGTH('text');
-> 4
Length()
ST_Length()
FILE
max_allowed_packet
secure_file_priv
NULL
character_set_filesystem
MySQL的> UPDATE t
SET blob_col=LOAD_FILE('/tmp/picture')
WHERE id=1;
LOCATE(
substr
,str
)LOCATE(
substr
,str
,pos
)
substr
str
substr
str
pos
substr
str
NULL
MySQL的> SELECT LOCATE('bar', 'foobarbar');
-> 4mysql>SELECT LOCATE('xbar', 'foobar');
-> 0mysql>SELECT LOCATE('bar', 'foobarbar', 5);
> 7
str
mysql> SELECT LOWER('QUADRATICALLY');
-> 'quadratically'
LOWER()
UPPER()
BINARY
VARBINARY
BLOB
MySQL的> SET @str = BINARY 'New York';
MySQL的> SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));
------------- ------------------------------------ |下(@ STR)|低(转换(@ STR使用utf8mb4))| ------------- ------------------------------------ |纽约|纽约| ------------- ------------------------------------
LOWER()
UPPER()
utf8_unicode_520_ci
LCASE()
str
padstr
len
str
len
len
MySQL的> SELECT LPAD('hi',4,'??');
-> '??hi'mysql>SELECT LPAD('hi',1,'??');
- >“H”
str
MySQL的> SELECT LTRIM(' barbar');
- >巴巴”
,
bits
str1
str2
str1
str2
mysql>SELECT MAKE_SET(1,'a','b','c');
-> 'a' mysql>SELECT MAKE_SET(1 | 4,'hello','nice','world');
-> 'hello,world' mysql>SELECT MAKE_SET(1 | 4,'hello','nice',NULL,'world');
-> 'hello' mysql>SELECT MAKE_SET(0,'a','b','c');
-> ''
N
N
BIGINT
CONV(
N
,10,8)N
mysql> SELECT OCT(12);
-> '14'
str
(第一字节编码)(第二字节码×256)(第三字节码* 256 ^ 2)…
ORD()
ASCII()
MySQL的> SELECT ORD('2');
-> 50
\
NUL
mysql>SELECT QUOTE('Don\'t!');
-> 'Don\'t!' mysql>SELECT QUOTE(NULL);
-> NULL
str
count
count
str
count
mysql> SELECT REPEAT('MySQL', 3);
-> 'MySQLMySQLMySQL'
str
from_str
to_str
REPLACE()
from_str
MySQL的> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
wwwwww.mysql.com’->’
str
MySQL的> SELECT REVERSE('abc');
- >“CBA”
len
str
NULL
MySQL的> SELECT RIGHT('foobarbar', 4);
- >“RBAR”
str
padstr
len
str
len
len
MySQL的> SELECT RPAD('hi',5,'?');
-> 'hi???'mysql>SELECT RPAD('hi',1,'?');
- >“H”
str
MySQL的> SELECT RTRIM('barbar ');
- >巴巴”
str
SOUNDEX()
SUBSTRING()
str
SOUNDEX()
gb3212
MySQL的> SELECT SOUNDEX('Hello');
-> 'H400'mysql>SELECT SOUNDEX('Quadratically');
q36324”- >“
N
MySQL的> SELECT SPACE(6);
- >”
SUBSTR(
str
,pos
)SUBSTR(
str
FROM pos
)SUBSTR(
str
,pos
,len
)SUBSTR(
str
FROM pos
FOR
len
)
SUBSTRING(
str
,pos
)SUBSTRING(
str
FROM pos
)SUBSTRING(
str
,pos
,len
)SUBSTRING(
str
FROM pos
FOR
len
)
len
str
pos
len
len
str
pos
pos
pos
pos
SUBSTRING()
mysql>SELECT SUBSTRING('Quadratically',5);
-> 'ratically' mysql>SELECT SUBSTRING('foobarbar' FROM 4);
-> 'barbar' mysql>SELECT SUBSTRING('Quadratically',5,6);
-> 'ratica' mysql>SELECT SUBSTRING('Sakila', -3);
-> 'ila' mysql>SELECT SUBSTRING('Sakila', -5, 3);
-> 'aki' mysql>SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
-> 'ki'
len
SUBSTRING_INDEX(
str
,delim
,count
)
str
count
delim
count
count
SUBSTRING_INDEX()
delim
MySQL的> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'mysql>SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
“MySQL”>
NULL
FROM_BASE64()
MySQL的> SELECT TO_BASE64('abc'), FROM_BASE64(TO_BASE64('abc'));
我是ABC jwjj >,是
TO_BASE64()
FROM_BASE64()
'+'
'/'
'='
TRIM([{BOTH | LEADING | TRAILING}
[
remstr
] FROM]
str
)TRIM([
remstr
FROM] str
)
str
remstr
LEADING
BOTH
remstr
MySQL的> SELECT TRIM(' bar ');
-> 'bar'mysql>SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
-> 'barxxx'mysql>SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
-> 'bar'mysql>SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
- >“BARX”
UCASE()
str
UNHEX(
str
)
MySQL的> SELECT UNHEX('4D7953514C');
-> 'MySQL'mysql>SELECT X'4D7953514C';
-> 'MySQL'mysql>SELECT UNHEX(HEX('string'));
-> 'string'mysql>SELECT HEX(UNHEX('1267'));
> 1267
'0'
'A'
'a'
NULL
MySQL的> SELECT UNHEX('GG');
------------- | unhex('gg”)| ------------- |空| -------------
NULL
UNHEX()
BINARY
CHAR(3)
'41'
UNHEX()
'41'
'41\0'
0x00
UNHEX()
N
HEX(
N
)UNHEX()
CONV(HEX(
N
),16,10)HEX()
str
mysql> SELECT UPPER('Hej');
-> 'HEJ'
LOWER()
UPPER()
BINARY
VARBINARY
BLOB
UCASE()
WEIGHT_STRING(
str
[AS {CHAR|BINARY}(N
)]
[flags
])
WEIGHT_STRING(
=str1
)WEIGHT_STRING(
str2
)str1
=str2
str1
str2
WEIGHT_STRING(
<str1
)WEIGHT_STRING(
str2
)str1
<str2
str1
str2
WEIGHT_STRING()
str
AS
flags
str
CHAR
VARCHAR
TEXT
BINARY
VARBINARY
BLOB
WEIGHT_STRING()
mysql>SET @s = _utf8mb4 'AB' COLLATE utf8mb4_0900_ai_ci;
mysql>SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s));
+------+---------+------------------------+ | @s | HEX(@s) | HEX(WEIGHT_STRING(@s)) | +------+---------+------------------------+ | AB | 4142 | 1C471C60 | +------+---------+------------------------+
MySQL的> SET @s = _utf8mb4 'ab' COLLATE utf8mb4_0900_ai_ci;
MySQL的> SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s));
------ --------- ------------------------ | @的|进制(氏)| hex(weight_string(氏))| ------ --------- ------------------------ | AB | 6162 | 1c471c60 | ------ --------- ------------------------
MySQL的> SET @s = CAST('AB' AS BINARY);
MySQL的> SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s));
------ --------- ------------------------ | @的|进制(氏)| hex(weight_string(氏))| ------ --------- ------------------------ | AB | 4142 | 4142 | ------ --------- ------------------------
MySQL的> SET @s = CAST('ab' AS BINARY);
MySQL的> SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s));
------ --------- ------------------------ | @的|进制(氏)| hex(weight_string(氏))| ------ --------- ------------------------ | AB | 6162 | 6162 | ------ --------- ------------------------
HEX()
WEIGHT_STRING()
HEX()
MySQL的> SET @s = CONVERT(X'C39F' USING utf8) COLLATE utf8_czech_ci;
MySQL的> SELECT HEX(WEIGHT_STRING(@s));
------------------------ | hex(weight_string(氏))| ------------------------ | 0fea0fea | ------------------------
NULL
VARBINARY
VARBINARY
BLOB
AS
AS CHAR(
N
)N
N
N
N
AS BINARY(
N
)N
mysql>SET NAMES 'latin1';
mysql>SELECT HEX(WEIGHT_STRING('ab' AS CHAR(4)));
+-------------------------------------+ | HEX(WEIGHT_STRING('ab' AS CHAR(4))) | +-------------------------------------+ | 41422020 | +-------------------------------------+ mysql>SET NAMES 'utf8';
mysql>SELECT HEX(WEIGHT_STRING('ab' AS CHAR(4)));
+-------------------------------------+ | HEX(WEIGHT_STRING('ab' AS CHAR(4))) | +-------------------------------------+ | 0041004200200020 | +-------------------------------------+
MySQL的> SELECT HEX(WEIGHT_STRING('ab' AS BINARY(4)));
--------------------------------------- | hex(weight_string('ab”二元(四)))| --------------------------------------- | 61620000 | ---------------------------------------
flags
expr
LIKE pat
[ESCAPE
'escape_char
']
1
0
expr
pat
NULL
LIKE
=
MySQL的> SELECT '?' LIKE 'ae' COLLATE latin1_german2_ci;
?| -----------------------------------------就像是AE是collate latin1 _ german2 _我们| ----------------------------------------- | | ----------------------------------------- MySQL>0 SELECT '?' = 'ae' COLLATE latin1_german2_ci;
+--------------------------------------+| '?' = 'ae' COLLATE latin1_german2_ci |+--------------------------------------+| 1 |+--------------------------------------+
CHAR
VARCHAR
=
MySQL的> SELECT 'a' = 'a ', 'a' LIKE 'a ';
+------------+---------------+| 'a' = 'a ' | 'a' LIKE 'a ' |+------------+---------------+| 1 | 0 |+------------+---------------+1 row in set (0.00 sec)
LIKE
%
_
MySQL的> SELECT 'David!' LIKE 'David_';
-> 1mysql>SELECT 'David!' LIKE '%D%v%';
-> 1
ESCAPE
\%
\_
mysql>SELECT 'David!' LIKE 'David\_';
-> 0 mysql>SELECT 'David_' LIKE 'David\_';
-> 1
ESCAPE
MySQL的> SELECT 'David_' LIKE 'David|_' ESCAPE '|';
-> 1
NO_BACKSLASH_ESCAPES
mysql>SELECT 'abc' LIKE 'ABC';
-> 1 mysql>SELECT 'abc' LIKE _utf8mb4 'ABC' COLLATE utf8mb4_0900_as_cs;
-> 0 mysql>SELECT 'abc' LIKE _utf8mb4 'ABC' COLLATE utf8mb4_bin;
-> 0 mysql>SELECT 'abc' LIKE BINARY 'ABC';
-> 0
LIKE
MySQL的> SELECT 10 LIKE '1%';
-> 1
\n
LIKE
\\n
\\\\
\\
MySQL的> SELECT filename FROM t1;
-------------- |文件名| -------------- | C:| | C:\ | | C:\程序| | C:\程序\ | --------------
mysql>SELECT filename, filename LIKE '%\\' FROM t1;
+--------------+---------------------+ | filename | filename LIKE '%\\' | +--------------+---------------------+ | C: | 0 | | C:\ | 1 | | C:\Programs | 0 | | C:\Programs\ | 1 | +--------------+---------------------+ mysql>SELECT filename, filename LIKE '%\\\\' FROM t1;
+--------------+-----------------------+ | filename | filename LIKE '%\\\\' | +--------------+-----------------------+ | C: | 0 | | C:\ | 1 | | C:\Programs | 0 | | C:\Programs\ | 1 | +--------------+-----------------------+
expr
NOT LIKE pat
[ESCAPE
'escape_char
']
NOT
(
expr
LIKE
pat
[ESCAPE
'escape_char
'])
NOT
LIKE
CREATE TABLE foo (bar VARCHAR(10)); INSERT INTO foo VALUES (NULL), (NULL);
SELECT COUNT(*) FROM foo WHERE bar LIKE
'%baz%';
SELECT COUNT(*) FROM foo WHERE bar
NOT LIKE '%baz%';
0
expr
expr
NOT
RLIKE
NOT
REGEXP
OR
AND
SELECT COUNT(*) FROM foo WHERE bar NOT LIKE '%baz%' OR bar IS NULL;
STRCMP()
-1
mysql>SELECT STRCMP('text', 'text2');
-> -1 mysql>SELECT STRCMP('text2', 'text');
-> 1 mysql>SELECT STRCMP('text', 'text');
-> 0
STRCMP()
MySQL的> SET @s1 = _utf8mb4 'x' COLLATE utf8mb4_0900_ai_ci;
MySQL的> SET @s2 = _utf8mb4 'X' COLLATE utf8mb4_0900_ai_ci;
MySQL的> SET @s3 = _utf8mb4 'x' COLLATE utf8mb4_0900_as_cs;
MySQL的> SET @s4 = _utf8mb4 'X' COLLATE utf8mb4_0900_as_cs;
MySQL的> SELECT STRCMP(@s1, @s2), STRCMP(@s3, @s4);
————| strcmp(@ @ S1,S2)| strcmp(@ @ S3,S4)|——————| | | 0 1。
mysql> SET @s1 = _utf8mb4 'x' COLLATE utf8mb4_0900_ai_ci; mysql> SET @s2 = _utf8mb4 'X' COLLATE utf8mb4_0900_ai_ci; mysql> SET @s3 = _utf8mb4 'x' COLLATE utf8mb4_0900_as_cs; mysql> SET @s4 = _utf8mb4 'X' COLLATE utf8mb4_0900_as_cs; --> mysql>SELECT STRCMP(@s1, @s3);
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_0900_as_cs,IMPLICIT) for operation 'strcmp' mysql>SELECT STRCMP(@s1, @s3 COLLATE utf8mb4_0900_ai_ci);
+---------------------------------------------+ | STRCMP(@s1, @s3 COLLATE utf8mb4_0900_ai_ci) | +---------------------------------------------+ | 0 | +---------------------------------------------+
NOT REGEXP | |
REGEXP | |
REGEXP_INSTR() | |
REGEXP_LIKE() | |
REGEXP_REPLACE() | |
REGEXP_SUBSTR() | |
RLIKE |
expr
NOT REGEXP pat
expr
NOT RLIKE pat
NOT
(
expr
REGEXP
pat
)
expr
REGEXP pat
expr
RLIKE pat
expr
pat
expr
pat
NULL
REGEXP_LIKE()
MySQL的> SELECT 'Michael!' REGEXP '.*';
的;|迈克尔!!!!!!!”regexp”。* |;| 1 | MySQL >; SELECT 'new*\n*line' REGEXP 'new\\*.\\*line';
| --------------------------------------- *新*在线N是New RegExp \\ \\**。| --------------------------------------- |线| --------------------------------------- MySQL>0 SELECT 'a' REGEXP '^[a-d]';
--------------------- | ' regexp的^ [广告]的| --------------------- | 1 | --------------------- MySQL > SELECT 'a' REGEXP 'A', 'a' REGEXP BINARY 'A';
---------------- ----------------------- | ' regexp ' | ' regexp二进制' | ---------------- ----------------------- | 1 | 0 | ---------------- -----------------------
REGEXP_INSTR(
expr
,
pat
[,
pos
[,
occurrence
[,
return_option
[,
match_type
]]]])
expr
pat
expr
pat
NULL
REGEXP_INSTR()
pos
expr
occurrence
return_option
REGEXP_INSTR()
REGEXP_INSTR()
match_type
REGEXP_LIKE()
REGEXP_LIKE()
MySQL的> SELECT REGEXP_INSTR('dog cat dog', 'dog');
------------------------------------ | regexp_instr('dog猫狗”,“狗”)| ------------------------------------ | 1 | ------------------------------------ MySQL > SELECT REGEXP_INSTR('dog cat dog', 'dog', 2);
--------------------------------------- | regexp_instr('dog猫狗”,“狗”,2)| --------------------------------------- | 9 | --------------------------------------- MySQL > SELECT REGEXP_INSTR('aa aaa aaaa', 'a{2}');
仪器| _ ------------------------------------- RegExp(AA AAA级”,“| {2})------------------------------------- | | MySQL ------------------------------------->1 SELECT REGEXP_INSTR('aa aaa aaaa', 'a{4}');
仪器| _ ------------------------------------- RegExp(AA AAA级”,“{ }”| ------------------------------------- | 4 8 | -------------------------------------)
REGEXP_LIKE(
expr
,
pat
[,
match_type
])
expr
pat
expr
pat
NULL
match_type
c
i
m
n
.
u
^
match_type
expr
pat
mysql>SELECT REGEXP_LIKE('CamelCase', 'CAMELCASE');
+---------------------------------------+ | REGEXP_LIKE('CamelCase', 'CAMELCASE') | +---------------------------------------+ | 1 | +---------------------------------------+ mysql>SELECT REGEXP_LIKE('CamelCase', 'CAMELCASE' COLLATE utf8mb4_0900_as_cs);
+------------------------------------------------------------------+ | REGEXP_LIKE('CamelCase', 'CAMELCASE' COLLATE utf8mb4_0900_as_cs) | +------------------------------------------------------------------+ | 0 | +------------------------------------------------------------------+
match_type
i
match_type
\n
expr
pat
MySQL的> SELECT REGEXP_LIKE('Michael!', '.*');
------------------------------- | regexp_like('michael!”,“*”)| ------------------------------- | 1 | ------------------------------- MySQL > SELECT REGEXP_LIKE('new*\n*line', 'new\\*.\\*line');
---------------------------------------------- | regexp_like(新* n *线','新\\ *。\\ *线”)| ---------------------------------------------- | 0 | ---------------------------------------------- MySQL > SELECT REGEXP_LIKE('a', '^[a-d]');
---------------------------- | regexp_like(“A”,“^ [广告]”)| ---------------------------- | 1 | ---------------------------- MySQL > SELECT REGEXP_LIKE('a', 'A'), REGEXP_LIKE('a', BINARY 'A');
----------------------- ------------------------------ | regexp_like(“A”,“A”)| regexp_like('a',二元')| ----------------------- ------------------------------ | 1 | 0 | ----------------------- ------------------------------
MySQL的> SELECT REGEXP_LIKE('abc', 'ABC');
--------------------------- | regexp_like(ABC,ABC)| --------------------------- | 1 | --------------------------- MySQL > SELECT REGEXP_LIKE('abc', 'ABC', 'c');
| regexp like _ --------------------------------(ABC,ABC,0 C)| -------------------------------- | | --------------------------------
REGEXP_REPLACE(
expr
,
pat
,
repl
[,
pos
[,
occurrence
[,
match_type
]]])
expr
pat
repl
expr
pat
repl
NULL
REGEXP_REPLACE()
pos
expr
occurrence
match_type
REGEXP_LIKE()
REGEXP_LIKE()
MySQL的> SELECT REGEXP_REPLACE('a b c', 'b', 'X');
----------------------------------- | regexp_replace(A B C”、“B”、“X”)| ----------------------------------- | X C | ----------------------------------- MySQL > SELECT REGEXP_REPLACE('abc def ghi', '[a-z]+', 'X', 1, 3);
---------------------------------------------------- | regexp replace(ABC _最终酥油,是[ ] A—Z,X,1,3)| ---------------------------------------------------- |最终---------------------------------------------------- X | ABC
REGEXP_SUBSTR(
expr
,
pat
[,
pos
[,
occurrence
[,
match_type
]]])
expr
pat
expr
pat
NULL
REGEXP_SUBSTR()
pos
expr
occurrence
match_type
REGEXP_LIKE()
REGEXP_LIKE()
MySQL的> SELECT REGEXP_SUBSTR('abc def ghi', '[a-z]+');
---------------------------------------- | regexp substr(ABC _最终酥油,〔Z〕)| ---------------------------------------- | ABC | ---------------------------------------- MySQL > SELECT REGEXP_SUBSTR('abc def ghi', '[a-z]+', 1, 3);
---------------------------------------------- | regexp substr(ABC _最终酥油,〔Z〕,1,3)| ---------------------------------------------- | | ----------------------------------------------酥油
hello
hello|world
hello
B[an]*s
Baaaaas
B
a
^
mysql>SELECT REGEXP_LIKE('fo\nfo', '^fo$');
-> 0 mysql>SELECT REGEXP_LIKE('fofo', '^fo');
-> 1
$
mysql>SELECT REGEXP_LIKE('fo\no', '^fo\no$');
-> 1 mysql>SELECT REGEXP_LIKE('fo\no', '^fo$');
-> 0
.
m
mysql>SELECT REGEXP_LIKE('fofo', '^f.*$');
-> 1 mysql>SELECT REGEXP_LIKE('fo\r\nfo', '^f.*$');
-> 0 mysql>SELECT REGEXP_LIKE('fo\r\nfo', '^f.*$', 'm');
-> 1 mysql>SELECT REGEXP_LIKE('fo\r\nfo', '(?m)^f.*$');
-> 1
a*
a
MySQL的> SELECT REGEXP_LIKE('Ban', '^Ba*n');
-> 1mysql>SELECT REGEXP_LIKE('Baaan', '^Ba*n');
-> 1mysql>SELECT REGEXP_LIKE('Bn', '^Ba*n');
-> 1
a+
a
MySQL的> SELECT REGEXP_LIKE('Ban', '^Ba+n');
-> 1mysql>SELECT REGEXP_LIKE('Bn', '^Ba+n');
> 0
a?
a
MySQL的> SELECT REGEXP_LIKE('Bn', '^Ba?n');
-> 1mysql>SELECT REGEXP_LIKE('Ban', '^Ba?n');
-> 1mysql>SELECT REGEXP_LIKE('Baan', '^Ba?n');
> 0
de|abc
de
mysql>SELECT REGEXP_LIKE('pi', 'pi|apa');
-> 1 mysql>SELECT REGEXP_LIKE('axe', 'pi|apa');
-> 0 mysql>SELECT REGEXP_LIKE('apa', 'pi|apa');
-> 1 mysql>SELECT REGEXP_LIKE('apa', '^(pi|apa)$');
-> 1 mysql>SELECT REGEXP_LIKE('pi', '^(pi|apa)$');
-> 1 mysql>SELECT REGEXP_LIKE('pix', '^(pi|apa)$');
-> 0
(abc)*
abc
MySQL的> SELECT REGEXP_LIKE('pi', '^(pi)*$');
-> 1mysql>SELECT REGEXP_LIKE('pip', '^(pi)*$');
-> 0mysql>SELECT REGEXP_LIKE('pipi', '^(pi)*$');
-> 1
{1}
{
n
}m
n
m
n
a*
a{0,}
a+
a{1,}
a?
a{0,1}
a{
n
}n
a{
n
,}n
a{
m
,n
}m
n
m
n
m
n
MySQL的> SELECT REGEXP_LIKE('abcde', 'a[bcd]{2}e');
-> 0mysql>SELECT REGEXP_LIKE('abcde', 'a[bcd]{3}e');
-> 1mysql>SELECT REGEXP_LIKE('abcde', 'a[bcd]{1,10}e');
-> 1
[a-dX]
^
b
d
-
]
-
mysql>SELECT REGEXP_LIKE('aXbc', '[a-dXYZ]');
-> 1 mysql>SELECT REGEXP_LIKE('aXbc', '^[a-dXYZ]$');
-> 0 mysql>SELECT REGEXP_LIKE('aXbc', '^[a-dXYZ]+$');
-> 1 mysql>SELECT REGEXP_LIKE('aXbc', '^[^a-dXYZ]+$');
-> 0 mysql>SELECT REGEXP_LIKE('gheis', '^[^a-dXYZ]+$');
-> 1 mysql>SELECT REGEXP_LIKE('gheisa', '^[^a-dXYZ]+$');
-> 0
[=character_class=]
[
[=character_class=]
(+)
[[=o=]]
[[=(+)=]]
[:character_class:]
[
[:character_class:]
alnum | |
alpha | |
blank | |
cntrl | |
digit | |
graph | |
lower | |
print | |
punct | |
space | |
upper | |
xdigit |
mysql>SELECT REGEXP_LIKE('justalnums', '[[:alnum:]]+');
-> 1 mysql>SELECT REGEXP_LIKE('!!', '[[:alnum:]]+');
-> 0
1+2
mysql>SELECT REGEXP_LIKE('1+2', '1+2');
-> 0 mysql>SELECT REGEXP_LIKE('1+2', '1\+2');
-> 0 mysql>SELECT REGEXP_LIKE('1+2', '1\\+2');
-> 1
REGEXP_LIKE()
regexp_stack_limit
regexp_time_limit
REGEXP
RLIKE
UTF-16
MySQL的> SELECT REGEXP_INSTR('????b', 'b');
-------------------------- | regexp _ instr(??????????????A”,“B”)| -------------------------- | 5 | -------------------------- 1排在集(0.00美国证券交易委员会(SEC)的MySQL > SELECT REGEXP_INSTR('????bxxx', 'b', 4);
-------------------------------- | regexp_instr('??气囊”,“B”,4)| -------------------------------- | 5 | -------------------------------- 1行集(0秒)
mysql>SELECT REGEXP_INSTR('бжb', 'b');
+----------------------------+ | REGEXP_INSTR('бжb', 'b') | +----------------------------+ | 3 | +----------------------------+ 1 row in set (0.00 sec) mysql>SELECT REGEXP_INSTR('??b', 'b');
+----------------------------+ | REGEXP_INSTR('??b', 'b') | +----------------------------+ | 3 | +----------------------------+ 1 row in set (0.00 sec) mysql>SELECT REGEXP_INSTR('μ?周?б', '周');
+------------------------------------+ | REGEXP_INSTR('μ?周?б', '周') | +------------------------------------+ | 3 | +------------------------------------+ 1 row in set (0.00 sec)
??
REGEXP_SUBSTR()
MySQL的> SELECT REGEXP_SUBSTR('周周周周', '.*', 2);
---------------------------------------- | regexp substr(_周周周周*,,。2)| ---------------------------------------- |周周周| ---------------------------------------- 1行集(0秒)在MySQL > SELECT REGEXP_SUBSTR('????????', '.*', 2);
-------------------------------- | regexp_substr('????',' * ',2)| -------------------------------- |??揘?揘?揘| -------------------------------- 1行集(0秒)
.
[[:<:]]
[.characters.]
{n}
regexp_time_limit
(
MySQL的> SELECT REGEXP_LIKE('(', '(');
错误3692(hy000):不匹配的括号中的正则表达式。MySQL > SELECT REGEXP_LIKE('(', '\\(');
------------------------- | regexp_like('(',' \(')| ------------------------- | 1 | -------------------------
UPPER(
X
)X
INSTR()
LCASE()
LOWER()
LTRIM()
MID()
REPEAT()
REPLACE()
REVERSE()
RIGHT()
RPAD()
RTRIM()
SOUNDEX()
SUBSTRING()
TRIM()
UCASE()
UPPER()
REPLACE()
binary
CHARSET()
COLLATION()
mysql> SELECT CHARSET(BINARY 'a'), COLLATION(BINARY 'a');
+---------------------+-----------------------+
| CHARSET(BINARY 'a') | COLLATION(BINARY 'a') |
+---------------------+-----------------------+
| binary | binary |
+---------------------+-----------------------+
COLLATE
Y
Y
COLLATE
Y
Z
Y
Y
CASE ... WHEN a THEN b WHEN b THEN c
COLLATE
X
ENDX
UNION
||
CONCAT()
ELT()
GREATEST()
IF()
LEAST()
character_set_connection
collation_connection
BIN_TO_UUID()
CAST()
CONV()
FORMAT()
HEX()
SPACE()
BIN_TO_UUID()
CONV()
HEX()
CHARSET()
COLLATION()
MySQL的> SELECT USER(), CHARSET(USER()), COLLATION(USER());
---------------- ----------------- ------------------- | user() |字符集(user())|整理(user())| ---------------- ----------------- ------------------- |测试@本地| UTF8 | utf8_general_ci | ---------------- ----------------- ------------------- MySQL > SELECT CHARSET(COMPRESS('abc')), COLLATION(COMPRESS('abc'));
-------------------------- ---------------------------- |字符集(压缩(ABC”))|整理(压缩(ABC”))| -------------------------- ---------------------------- |二进制|二进制| -------------------------- ----------------------------
ABS() | |
ACOS() | |
ASIN() | |
ATAN() | |
ATAN2()
| |
CEIL() | |
CEILING() | |
CONV() | |
COS() | |
COT() | |
CRC32() | |
DEGREES() | |
DIV | |
/ | |
EXP() | |
FLOOR() | |
LN() | |
LOG() | |
LOG10() | |
LOG2() | |
- | |
MOD() | |
%
| |
PI() | |
+ | |
POW() | |
POWER() | |
RADIANS() | |
RAND() | |
ROUND() | |
SIGN() | |
SIN() | |
SQRT() | |
TAN() | |
* | |
TRUNCATE() | |
- |
(14620 / 9432456) / (24250 / 9432456)
0.60288653
DATE_ADD()
mysql> SELECT 3+5;
-> 8
mysql> SELECT 3-5;
-> -2
mysql> SELECT - 2;
-> -2
mysql>SELECT 3*5;
-> 15 mysql>SELECT 18014398509481984*18014398509481984.0;
-> 324518553658426726783156020576256.0 mysql>SELECT 18014398509481984*18014398509481984;
-> out-of-range error
BIGINT
mysql> SELECT 3/5;
-> 0.60
NULL
MySQL的> SELECT 102/(1-1);
>0
BIGINT
DECIMAL
DECIMAL
BIGINT
mysql> SELECT 5 DIV 2, -5 DIV 2, 5 DIV -2, -5 DIV -2;
-> 2, -2, -2, 2
N
M
MOD()
ABS() | |
ACOS() | |
ASIN() | |
ATAN() | |
ATAN2()
| |
CEIL() | |
CEILING() | |
CONV() | |
COS() | |
COT() | |
CRC32() | |
DEGREES() | |
EXP() | |
FLOOR() | |
LN() | |
LOG() | |
LOG10() | |
LOG2() | |
MOD() | |
PI() | |
POW() | |
POWER() | |
RADIANS() | |
RAND() | |
ROUND() | |
SIGN() | |
SIN() | |
SQRT() | |
TAN() | |
TRUNCATE() |
NULL
X
MySQL的> SELECT ABS(2);
-> 2mysql>SELECT ABS(-32);
> 32
BIGINT
X
X
X
1
MySQL的> SELECT ACOS(1);
-> 0mysql>SELECT ACOS(1.0001);
-> NULLmysql>SELECT ACOS(0);
> 1.5707963267949
X
X
X
1
MySQL的> SELECT ASIN(0.2);
-> 0.20135792079033mysql>SELECT ASIN('foo');
------------- |阿辛('foo”)| ------------- | 0 | ------------- 1行集,1报警(0秒)MySQL > SHOW WARNINGS;
--------- ------ ----------------------------------------- |水平|代码|消息| --------- ------ ----------------------------------------- |警告| 1292 |截断错误的双重价值:foo | --------- ------ -----------------------------------------
X
X
MySQL的> SELECT ATAN(2);
-> 1.1071487177941mysql>SELECT ATAN(-2);
-> -1.1071487177941
X
Y
Y
X
MySQL的> SELECT ATAN(-2,2);
-> -0.78539816339745mysql>SELECT ATAN2(PI(),0);
> 1.5707963267949
X
MySQL的> SELECT CEILING(1.23);
-> 2mysql>SELECT CEILING(-1.23);
> 1
N
from_base
to_base
NULL
N
36
from_base
N
N
CONV()
MySQL的> SELECT CONV('a',16,2);
-> '1010'mysql>SELECT CONV('6E',18,8);
-> '172'mysql>SELECT CONV(-17,10,-18);
-> '-H'mysql>SELECT CONV(10+'10'+'10'+X'0a',10,10);
- >“40”
X
X
MySQL的> SELECT COS(PI());
> 1
X
MySQL的> SELECT COT(12);
-> -1.5726734063977mysql>SELECT COT(0);
->超出范围的错误
NULL
mysql>SELECT CRC32('MySQL');
-> 3259397556 mysql>SELECT CRC32('mysql');
-> 2501908538
X
MySQL的> SELECT DEGREES(PI());
-> 180mysql>SELECT DEGREES(PI() / 2);
> 90
X
LOG()
LN()
MySQL的> SELECT EXP(2);
-> 7.3890560989307mysql>SELECT EXP(-2);
-> 0.13533528323661mysql>SELECT EXP(0);
-> 1
X
MySQL的> SELECT FLOOR(1.23), FLOOR(-1.23);
- 1 - 2
X
D
X
X
X
mysql>SELECT LN(2);
-> 0.69314718055995 mysql>SELECT LN(-2);
-> NULL
X
X
EXP()
MySQL的> SELECT LOG(2);
-> 0.69314718055995mysql>SELECT LOG(-2);
>0
X
B
X
B
mysql>SELECT LOG(2,65536);
-> 16 mysql>SELECT LOG(10,100);
-> 2 mysql>SELECT LOG(1,100);
-> NULL
X
X
mysql>SELECT LOG2(65536);
-> 16 mysql>SELECT LOG2(-100);
-> NULL
LOG2()
LOG(
X
) /
LOG(2)
X
X
mysql>SELECT LOG10(2);
-> 0.30102999566398 mysql>SELECT LOG10(100);
-> 2 mysql>SELECT LOG10(-100);
-> NULL
N
M
MySQL的> SELECT MOD(234, 10);
-> 4mysql>SELECT 253 % 7;
-> 1mysql>SELECT MOD(29,9);
-> 2mysql>SELECT 29 MOD 9;
> 2
BIGINT
MOD()
MySQL的> SELECT MOD(34.5,3);
> 1.5
MOD(
N
,0)
mysql>SELECT PI();
-> 3.141593 mysql>SELECT PI()+0.000000000000000000;
-> 3.141592653589793116
X
Y
MySQL的> SELECT POW(2,2);
-> 4mysql>SELECT POW(2,-2);
> 0.25
POW()
X
MySQL的> SELECT RADIANS(90);
> 1.5707963267949
v
<=v
<R
i
<=R
<j
FLOOR(
i
+ RAND() * (j
i
<=R
<
SELECT FLOOR(7 + (RAND() * 5));
N
RAND()
RAND(
N
)
mysql>CREATE TABLE t (i INT);
Query OK, 0 rows affected (0.42 sec) mysql>INSERT INTO t VALUES(1),(2),(3);
Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql>SELECT i, RAND() FROM t;
+------+------------------+ | i | RAND() | +------+------------------+ | 1 | 0.61914388706828 | | 2 | 0.93845168309142 | | 3 | 0.83482678498591 | +------+------------------+ 3 rows in set (0.00 sec) mysql>SELECT i, RAND(3) FROM t;
+------+------------------+ | i | RAND(3) | +------+------------------+ | 1 | 0.90576975597606 | | 2 | 0.37307905813035 | | 3 | 0.14808605345719 | +------+------------------+ 3 rows in set (0.00 sec) mysql>SELECT i, RAND() FROM t;
+------+------------------+ | i | RAND() | +------+------------------+ | 1 | 0.35877890638893 | | 2 | 0.28941420772058 | | 3 | 0.37073435016976 | +------+------------------+ 3 rows in set (0.00 sec) mysql>SELECT i, RAND(3) FROM t;
+------+------------------+ | i | RAND(3) | +------+------------------+ | 1 | 0.90576975597606 | | 2 | 0.37307905813035 | | 3 | 0.14808605345719 | +------+------------------+ 3 rows in set (0.01 sec)
RAND()
RAND()
RAND()
GROUP
BY
RAND()
SELECT * FROM tbl_name
为了rand();
ORDER BY RAND()
SELECT * FROM table1, table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000;
RAND()
binlog_format
X
D
X
D
D
D
X
MySQL的> SELECT ROUND(-1.23);
-> -1mysql>SELECT ROUND(-1.58);
-> -2mysql>SELECT ROUND(1.58);
-> 2mysql>SELECT ROUND(1.298, 1);
-> 1.3mysql>SELECT ROUND(1.298, 0);
-> 1mysql>SELECT ROUND(23.298, -1);
-> 20
mysql> SELECT ROUND(150.000,2), ROUND(150,2);
+------------------+--------------+
| ROUND(150.000,2) | ROUND(150,2) |
+------------------+--------------+
| 150.00 | 150 |
+------------------+--------------+
ROUND()
mysql> SELECT ROUND(2.5), ROUND(25E-1);
+------------+--------------+
| ROUND(2.5) | ROUND(25E-1) |
+------------+--------------+
| 3 | 2 |
+------------+--------------+
-1
1
X
MySQL的> SELECT SIGN(-32);
-> -1mysql>SELECT SIGN(0);
-> 0mysql>SELECT SIGN(234);
-> 1
X
X
MySQL的> SELECT SIN(PI());
-> 1.2246063538224e-16mysql>SELECT ROUND(SIN(PI()));
> 0
X
MySQL的> SELECT SQRT(4);
-> 2mysql>SELECT SQRT(20);
-> 4.4721359549996mysql>SELECT SQRT(-16);
>0
X
X
MySQL的> SELECT TAN(PI());
-> -1.2246063538224e-16mysql>SELECT TAN(PI()+1);
-> 1.5574077246549
X
D
D
D
D
X
MySQL的> SELECT TRUNCATE(1.223,1);
-> 1.2mysql>SELECT TRUNCATE(1.999,1);
-> 1.9mysql>SELECT TRUNCATE(1.999,0);
-> 1mysql>SELECT TRUNCATE(-1.999,1);
-> -1.9mysql>SELECT TRUNCATE(122,-2);
-> 100mysql>SELECT TRUNCATE(10.28*100,0);
> 1028
date_col
MySQL的> SELECT
something
FROMtbl_name
-> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <=
date_col
;
NOW()
CURDATE()
CURTIME()
UTC_DATE()
UTC_TIME()
UTC_TIMESTAMP()
CURRENT_TIMESTAMP()
CURRENT_TIME()
CURRENT_DATE()
FROM_UNIXTIME()
time_zone
UNIX_TIMESTAMP()
'2001-11-00'
MySQL的> SELECT DAYOFMONTH('2001-11-00'), MONTH('2005-00-00');
> 0、0
NULL
MySQL的> SELECT DATE_ADD('2006-05-00',INTERVAL 1 DAY);
-> NULLmysql>SELECT DAYNAME('2006-05-00');
>0
DATE()
CONVERT_TZ()
DATE_ADD()
DATE_SUB()
DAYOFYEAR()
LAST_DAY()
TIMESTAMPDIFF()
TO_DAYS()
TO_SECONDS()
WEEK()
WEEKDAY()
WEEKOFYEAR()
YEARWEEK()
TIME
TIMESTAMP
ADDDATE(
date
,INTERVAL
expr
unit
)ADDDATE(
expr
,days
)
INTERVAL
ADDDATE()
DATE_ADD()
SUBDATE()
DATE_SUB()
unit
DATE_ADD()
MySQL的> SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY);
-> '2008-02-02'mysql>SELECT ADDDATE('2008-01-02', INTERVAL 31 DAY);
- >“2008-02-02”
days
expr
MySQL的> SELECT ADDDATE('2008-01-02', 31);
- >“2008-02-02”
ADDTIME()
expr2
expr1
expr1
expr2
MySQL的> SELECT ADDTIME('2007-12-31 23:59:59.999999', '1 1:1:1.000002');
-> '2008-01-02 01:01:01.000001'mysql>SELECT ADDTIME('01:00:00.999999', '02:00:00.999998');
“99999 7”03:00:01. ->
CONVERT_TZ()
dt
from_tz
to_tz
NULL
TIMESTAMP
from_tz
TIMESTAMP
mysql>SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
-> '2004-01-01 13:00:00' mysql>SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00');
-> '2004-01-01 22:00:00'
'MET'
'YYYY-MM-DD'
mysql>SELECT CURDATE();
-> '2008-06-13' mysql>SELECT CURDATE() + 0;
-> 20080613
'HH:MM:SS'
fsp
MySQL的> SELECT CURTIME();
-> '23:50:26'mysql>SELECT CURTIME() + 0;
> 235026
expr
MySQL的> SELECT DATE('2003-12-31 01:02:03');
- >“2003-12-31”
DATEDIFF()
expr1
expr2
expr1
expr2
MySQL的> SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
-> 1mysql>SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');
> 31
DATE_ADD(
date
,INTERVAL
expr
unit
)DATE_SUB(
date
,INTERVAL
expr
unit
)
date
expr
expr
unit
INTERVAL
unit
expr
unit
unit | expr |
---|---|
MICROSECOND | MICROSECONDS |
SECOND | SECONDS |
MINUTE | MINUTES |
HOUR | HOURS |
DAY | DAYS |
WEEK | WEEKS |
MONTH | MONTHS |
QUARTER | QUARTERS |
YEAR | YEARS |
SECOND_MICROSECOND | 'SECONDS.MICROSECONDS' |
MINUTE_MICROSECOND | 'MINUTES:SECONDS.MICROSECONDS' |
MINUTE_SECOND | 'MINUTES:SECONDS' |
HOUR_MICROSECOND | 'HOURS:MINUTES:SECONDS.MICROSECONDS' |
HOUR_SECOND | 'HOURS:MINUTES:SECONDS' |
HOUR_MINUTE | 'HOURS:MINUTES' |
DAY_MICROSECOND | 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS' |
DAY_SECOND | 'DAYS HOURS:MINUTES:SECONDS' |
DAY_MINUTE | 'DAYS HOURS:MINUTES' |
DAY_HOUR | 'DAYS HOURS' |
YEAR_MONTH | 'YEARS-MONTHS' |
DATETIME
CAST()
DATETIME
expr
date
DATE
MONTH
DATE
DATETIME
date
区间 expr
unit
日期 区间 expr
unit
INTERVAL
expr
unit
+
-
expr
unit
MySQL的> SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
-> '2009-01-01 00:00:00'mysql>SELECT INTERVAL 1 DAY + '2008-12-31';
-> '2009-01-01'mysql>SELECT '2005-01-01' - INTERVAL 1 SECOND;
-> '2004-12-31 23:59:59'mysql>SELECT DATE_ADD('2000-12-31 23:59:59',
-> INTERVAL 1 SECOND);
-> '2001-01-01 00:00:00'mysql>SELECT DATE_ADD('2010-12-31 23:59:59',
-> INTERVAL 1 DAY);
-> '2011-01-01 23:59:59'mysql>SELECT DATE_ADD('2100-12-31 23:59:59',
-> INTERVAL '1:1' MINUTE_SECOND);
-> '2101-01-01 00:01:00'mysql>SELECT DATE_SUB('2005-01-01 00:00:00',
-> INTERVAL '1 1:1:1' DAY_SECOND);
-> '2004-12-30 22:58:59'mysql>SELECT DATE_ADD('1900-01-01 00:00:00',
-> INTERVAL '-1 10' DAY_HOUR);
-> '1899-12-30 14:00:00'mysql>SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
-> '1997-12-02'mysql>SELECT DATE_ADD('1992-12-31 23:59:59.000002',
-> INTERVAL '1.999999' SECOND_MICROSECOND);
- >“1993-01-01 00:00:01. 00000 1
unit
unit
expr
'1:10' DAY_SECOND
TIME
expr
HOUR_MINUTE
1.5000
MySQL的> SELECT 6/4;
-> 1.5000mysql>SELECT DATE_ADD('2009-01-01', INTERVAL 6/4 HOUR_MINUTE);
- >“2009-01-04 12:20:00”
CAST()
DECIMAL
MySQL的> SELECT CAST(6/4 AS DECIMAL(3,1));
-> 1.5mysql>SELECT DATE_ADD('1970-01-01 12:00:00',
-> INTERVAL CAST(6/4 AS DECIMAL(3,1)) HOUR_MINUTE);
- >“1970-01-01 13:05:00”
mysql>SELECT DATE_ADD('2013-01-01', INTERVAL 1 DAY);
-> '2013-01-02' mysql>SELECT DATE_ADD('2013-01-01', INTERVAL 1 HOUR);
-> '2013-01-01 01:00:00'
MONTH
YEAR
MySQL的> SELECT DATE_ADD('2009-01-30', INTERVAL 1 MONTH);
- >“2009-02-28”
'2006-07-00'
MySQL的> SELECT DATE_ADD('2006-07-00', INTERVAL 1 DAY);
-> NULLmysql>SELECT '2005-03-32' + INTERVAL 1 MONTH;
>0
date
format
format
%a | Sun
|
%b | Jan
|
%c | 0
|
%D | 0th
2nd
|
%d | 00
|
%e | 0
|
%f | 000000
|
%H | 00
|
%h | 01
|
%I | 01
|
%i | 00
|
%j | 001
|
%k | 0
|
%l | 1
|
%M | January
|
%m | 00
|
%p | AM
|
%r | hh:mm:ss
PM |
%S | 00
|
%s | 00
|
%T | hh:mm:ss |
%U | 00
WEEK() |
%u | 00
WEEK() |
%V | 01
WEEK()
|
%v | 01
WEEK()
|
%W | Sunday
|
%w | 0 =Sunday.. =Saturday) |
%X | %V |
%x | %v |
%Y | |
%y | |
%% | % |
% | x x |
'2014-00-00'
lc_time_names
%U
%V
WEEK()
DATE_FORMAT()
character_set_connection
collation_connection
MySQL的> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
-> 'Sunday October 2009'mysql>SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00'mysql>SELECT DATE_FORMAT('1900-10-04 22:23:00',
-> '%D %y %a %d %m %b %j');
-> '4th 00 Thu 04 10 Oct 277'mysql>SELECT DATE_FORMAT('1997-10-04 22:23:00',
-> '%H %k %I %r %T %S %w');
-> '22 22 10 10:23:00 PM 22:23:00 00 6'mysql>SELECT DATE_FORMAT('1999-01-01', '%X %V');
-> '1998 52'mysql>SELECT DATE_FORMAT('2006-06-00', '%d');
- >“00”
DATE_SUB(
date
,INTERVAL
expr
unit
)
DATE_ADD()
date
lc_time_names
mysql> SELECT DAYNAME('2007-02-03');
-> 'Saturday'
date
31
'0000-00-00'
mysql> SELECT DAYOFMONTH('2007-02-03');
-> 3
date
= Sunday,2
= Monday, …,
= Saturday). These index values correspond to the ODBC standard.
mysql> SELECT DAYOFWEEK('2007-02-03');
-> 7
date
366
MySQL的> SELECT DAYOFYEAR('2007-02-03');
> 34
EXTRACT()
DATE_ADD()
DATE_SUB()
MySQL的> SELECT EXTRACT(YEAR FROM '2009-07-02');
-> 2009mysql>SELECT EXTRACT(YEAR_MONTH FROM '2009-07-02 01:02:03');
-> 200907mysql>SELECT EXTRACT(DAY_MINUTE FROM '2009-07-02 01:02:03');
-> 20102mysql>SELECT EXTRACT(MICROSECOND
-> FROM '2003-01-02 10:30:00.000123');
> 123
N
DATE
MySQL的> SELECT FROM_DAYS(730669);
- >“2000-07-03”
FROM_DAYS()
FROM_UNIXTIME(
unix_timestamp
)FROM_UNIXTIME(
unix_timestamp
,format
)
unix_timestamp
YYYYMMDDHHMMSS
unix_timestamp
UNIX_TIMESTAMP()
format
format
DATE_FORMAT()
MySQL的> SELECT FROM_UNIXTIME(1447430881);
-> '2015-11-13 10:08:01'mysql>SELECT FROM_UNIXTIME(1447430881) + 0;
-> 20151113100801mysql>SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(),
-> '%Y %D %M %h:%i:%s %x');
- >“2015年11月13日10:08:01 2015年”
UNIX_TIMESTAMP()
FROM_UNIXTIME()
TIMESTAMP
UNIX_TIMESTAMP()
GET_FORMAT({DATE|TIME|DATETIME},
{'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL'})
DATE_FORMAT()
STR_TO_DATE()
DATE_FORMAT()
GET_FORMAT(DATE,'USA') | '%m.%d.%Y' |
GET_FORMAT(DATE,'JIS') | '%Y-%m-%d' |
GET_FORMAT(DATE,'ISO') | '%Y-%m-%d' |
GET_FORMAT(DATE,'EUR') | '%d.%m.%Y' |
GET_FORMAT(DATE,'INTERNAL') | '%Y%m%d' |
GET_FORMAT(DATETIME,'USA') | '%Y-%m-%d %H.%i.%s' |
GET_FORMAT(DATETIME,'JIS') | '%Y-%m-%d %H:%i:%s' |
GET_FORMAT(DATETIME,'ISO') | '%Y-%m-%d %H:%i:%s' |
GET_FORMAT(DATETIME,'EUR') | '%Y-%m-%d %H.%i.%s' |
GET_FORMAT(DATETIME,'INTERNAL') | '%Y%m%d%H%i%s' |
GET_FORMAT(TIME,'USA') | '%h:%i:%s %p' |
GET_FORMAT(TIME,'JIS') | '%H:%i:%s' |
GET_FORMAT(TIME,'ISO') | '%H:%i:%s' |
GET_FORMAT(TIME,'EUR') | '%H.%i.%s' |
GET_FORMAT(TIME,'INTERNAL') | '%H%i%s' |
TIMESTAMP
GET_FORMAT()
DATETIME
MySQL的> SELECT DATE_FORMAT('2003-10-03',GET_FORMAT(DATE,'EUR'));
-> '03.10.2003'mysql>SELECT STR_TO_DATE('10.31.2003',GET_FORMAT(DATE,'USA'));
- >“2003-10-31”
time
23
TIME
23
MySQL的> SELECT HOUR('10:05:03');
-> 10mysql>SELECT HOUR('272:59:59');
> 272
NULL
MySQL的> SELECT LAST_DAY('2003-02-05');
-> '2003-02-28'mysql>SELECT LAST_DAY('2004-02-05');
-> '2004-02-29'mysql>SELECT LAST_DAY('2004-01-01 01:01:01');
-> '2004-01-31'mysql>SELECT LAST_DAY('2003-03-32');
>0
dayofyear
mysql>SELECT MAKEDATE(2011,31), MAKEDATE(2011,32);
-> '2011-01-31', '2011-02-01' mysql>SELECT MAKEDATE(2011,365), MAKEDATE(2014,365);
-> '2011-12-31', '2014-12-31' mysql>SELECT MAKEDATE(2011,0);
-> NULL
hour
minute
second
second
MySQL的> SELECT MAKETIME(12,15,30);
- >“12:15:30”
expr
999999
MySQL的> SELECT MICROSECOND('12:00:00.123456');
-> 123456mysql>SELECT MICROSECOND('2009-12-31 23:59:59.000010');
> 10
time
59
MySQL的> SELECT MINUTE('2008-02-03 10:05:03');
> 5
date
12
'0000-00-00'
mysql> SELECT MONTH('2008-02-03');
-> 2
date
lc_time_names
mysql> SELECT MONTHNAME('2008-02-03');
-> 'February'
'YYYY-MM-DD HH:MM:SS'
fsp
MySQL的> SELECT NOW();
-> '2007-12-15 23:50:26'mysql>SELECT NOW() + 0;
-> 20071215235026.000000
NOW()
NOW()
SYSDATE()
MySQL的> SELECT NOW(), SLEEP(2), NOW();
--------------------- ---------- --------------------- | now() |睡眠(2)| now() | --------------------- ---------- --------------------- | 2006-04-12 13:47:36 | 0 | 2006-04-12 13:47:36 | --------------------- ---------- --------------------- MySQL > SELECT SYSDATE(), SLEEP(2), SYSDATE();
Syska()Sysday()Sleep(2)Systime(2)Sysday()Proceedings of 2009-04-12 13 : 47 : 44 pastès 0 disch a 2006-04-12 13 : 47 : 46 Proceedings
SET TIMESTAMP
NOW()
SYSDATE()
SYSDATE()
NOW()
NOW()
SYSDATE()
N
P
YYYYMM
P
mysql> SELECT PERIOD_ADD(200801,2);
-> 200803
P1
P2
P1
P2
YYYYMM
P1
P2
mysql> SELECT PERIOD_DIFF(200802,200703);
-> 11
date
4
MySQL的> SELECT QUARTER('2008-04-01');
> 2
time
59
MySQL的> SELECT SECOND('10:05:03');
->三
seconds
TIME
TIME
MySQL的> SELECT SEC_TO_TIME(2378);
-> '00:39:38'mysql>SELECT SEC_TO_TIME(2378) + 0;
> 3938
DATE_FORMAT()
str
format
STR_TO_DATE()
DATETIME
DATE
TIME
str
STR_TO_DATE()
str
format
format
str
format
str
format
DATE_FORMAT()
MySQL的> SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y');
-> '2013-05-01'mysql>SELECT STR_TO_DATE('May 1, 2013','%M %d,%Y');
- >“2013-05-01”
str
format
str
MySQL的> SELECT STR_TO_DATE('a09:30:17','a%h:%i:%s');
-> '09:30:17'mysql>SELECT STR_TO_DATE('a09:30:17','%h:%i:%s');
-> NULLmysql>SELECT STR_TO_DATE('09:30:17a','%h:%i:%s');
- >“09:30:17”
str
MySQL的> SELECT STR_TO_DATE('abc','abc');
-> '0000-00-00'mysql>SELECT STR_TO_DATE('9','%m');
-> '0000-09-00'mysql>SELECT STR_TO_DATE('9','%s');
- >“00:00:09”
mysql>SELECT STR_TO_DATE('00/00/0000', '%m/%d/%Y');
-> '0000-00-00' mysql>SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y');
-> '2004-04-31'
NO_ZERO_DATE
NO_ZERO_IN_DATE
STR_TO_DATE()
mysql>SET sql_mode = '';
mysql>SELECT STR_TO_DATE('15:35:00', '%H:%i:%s');
+-------------------------------------+ | STR_TO_DATE('15:35:00', '%H:%i:%s') | +-------------------------------------+ | 15:35:00 | +-------------------------------------+ mysql>SET sql_mode = 'NO_ZERO_IN_DATE';
mysql>SELECT STR_TO_DATE('15:35:00', '%h:%i:%s');
+-------------------------------------+ | STR_TO_DATE('15:35:00', '%h:%i:%s') | +-------------------------------------+ | NULL | +-------------------------------------+ mysql>SHOW WARNINGS\G
*************************** 1. row *************************** Level: Warning Code: 1411 Message: Incorrect datetime value: '15:35:00' for function str_to_date
"%X%V"
MySQL的> SELECT STR_TO_DATE('200442 Monday', '%X%V %W');
- >“2004-10-18”
SUBDATE(
date
,INTERVAL
expr
unit
)SUBDATE(
expr
,days
)
INTERVAL
SUBDATE()
DATE_SUB()
unit
DATE_ADD()
MySQL的> SELECT DATE_SUB('2008-01-02', INTERVAL 31 DAY);
-> '2007-12-02'mysql>SELECT SUBDATE('2008-01-02', INTERVAL 31 DAY);
- >“2007-12-02”
days
expr
MySQL的> SELECT SUBDATE('2008-01-02 12:00:00', 31);
- >“2007-12-02 12:00:00”
SUBTIME()
expr1
expr2
expr1
expr1
expr2
MySQL的> SELECT SUBTIME('2007-12-31 23:59:59.999999','1 1:1:1.000002');
-> '2007-12-30 22:58:58.999997'mysql>SELECT SUBTIME('01:00:00.999999', '02:00:00.999998');
- >”00:59:59. 999999
'YYYY-MM-DD HH:MM:SS'
fsp
SYSDATE()
NOW()
NOW()
MySQL的> SELECT NOW(), SLEEP(2), NOW();
--------------------- ---------- --------------------- | now() |睡眠(2)| now() | --------------------- ---------- --------------------- | 2006-04-12 13:47:36 | 0 | 2006-04-12 13:47:36 | --------------------- ---------- --------------------- MySQL > SELECT SYSDATE(), SLEEP(2), SYSDATE();
Syska()Sysday()Sleep(2)Systime(2)Sysday()Proceedings of 2009-04-12 13 : 47 : 44 pastès 0 disch a 2006-04-12 13 : 47 : 46 Proceedings
SET TIMESTAMP
NOW()
SYSDATE()
SYSDATE()
SYSDATE()
--sysdate-is-now
SYSDATE()
NOW()
SYSDATE()
expr
binlog_format
mysql>SELECT TIME('2003-12-31 01:02:03');
-> '01:02:03' mysql>SELECT TIME('2003-12-31 01:02:03.000123');
-> '01:02:03.000123'
TIMEDIFF()
expr1
expr2
expr1
expr2
TIMEDIFF()
TIME
TIMESTAMPDIFF()
UNIX_TIMESTAMP()
MySQL的> SELECT TIMEDIFF('2000:01:01 00:00:00',
-> '2000:01:01 00:00:00.000001');
-> '-00:00:00.000001'mysql>SELECT TIMEDIFF('2008-12-31 23:59:59.000001',
-> '2008-12-30 01:01:01.000002');
- >“46:58:57. 999999
TIMESTAMP(
expr
)TIMESTAMP(
expr1
,expr2
)
expr
expr2
expr1
MySQL的> SELECT TIMESTAMP('2003-12-31');
-> '2003-12-31 00:00:00'mysql>SELECT TIMESTAMP('2003-12-31 12:00:00','12:00:00');
- >“2004-01-01 00:00:00”
TIMESTAMPADD(
unit
,interval
,datetime_expr
)
interval
datetime_expr
interval
unit
SECOND
HOUR
WEEK
QUARTER
unit
DAY
mysql>SELECT TIMESTAMPADD(MINUTE,1,'2003-01-02');
-> '2003-01-02 00:01:00' mysql>SELECT TIMESTAMPADD(WEEK,1,'2003-01-02');
-> '2003-01-09'
TIMESTAMPDIFF(
unit
,datetime_expr1
,datetime_expr2
)
datetime_expr2
datetime_expr1
datetime_expr1
datetime_expr2
unit
unit
TIMESTAMPADD()
MySQL的> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
-> 3mysql>SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');
-> -1mysql>SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55');
> 128885
TIMESTAMP()
DATE_FORMAT()
format
0
time
%H
0..23
MySQL的> SELECT TIME_FORMAT('100:00:00', '%H %k %h %I %l');
> 100 100 04 04 4
time
MySQL的> SELECT TIME_TO_SEC('22:23:00');
-> 80580mysql>SELECT TIME_TO_SEC('00:39:38');
> 2378
date
MySQL的> SELECT TO_DAYS(950501);
-> 728779mysql>SELECT TO_DAYS('2007-10-07');
-> 733321
TO_DAYS()
'2008-10-07'
mysql> SELECT TO_DAYS('2008-10-07'), TO_DAYS('08-10-07');
-> 733687, 733687
'0000-00-00'
'0000-01-01'
TO_DAYS()
MySQL的> SELECT TO_DAYS('0000-00-00');
----------------------- | to_days('0000-00-00”)| ----------------------- |空| ----------------------- 1行集,1报警(0秒)MySQL > SHOW WARNINGS;
--------- ------ ---------------------------------------- |水平|代码|消息| --------- ------ ---------------------------------------- |警告| 1292 |错误:“0000-00-00 DateTime值的| --------- ------ ---------------------------------------- 1行集(0秒)MySQL > SELECT TO_DAYS('0000-01-01');
----------------------- | to_days('0000-01-01”)| ----------------------- | 1 | ----------------------- 1行集(0秒)
ALLOW_INVALID_DATES
expr
expr
mysql>SELECT TO_SECONDS(950501);
-> 62966505600 mysql>SELECT TO_SECONDS('2009-11-29');
-> 63426672000 mysql>SELECT TO_SECONDS('2009-11-29 13:43:32');
-> 63426721412 mysql>SELECT TO_SECONDS( NOW() );
-> 63426721458
TO_DAYS()
TO_DAYS()
'0000-00-00'
'0000-01-01'
TO_SECONDS()
MySQL的> SELECT TO_SECONDS('0000-00-00');
-------------------------- | to_seconds('0000-00-00”)| -------------------------- |空| -------------------------- 1行集,警告(0.001秒)MySQL > SHOW WARNINGS;
--------- ------ ---------------------------------------- |水平|代码|消息| --------- ------ ---------------------------------------- |警告| 1292 |错误:“0000-00-00 DateTime值的| --------- ------ ---------------------------------------- 1行集(0秒)MySQL > SELECT TO_SECONDS('0000-01-01');
-------------------------- | to_seconds('0000-01-01”)| -------------------------- | 86400 | -------------------------- 1行集(0秒)
ALLOW_INVALID_DATES
UNIX_TIMESTAMP()
UNIX_TIMESTAMP(
date
)
'1970-01-01 00:00:00'
DECIMAL
UNIX_TIMESTAMP()
date
date
DATE
DATETIME
TIMESTAMP
YYMMDDHHMMSS
YYYYMMDDHHMMSS
date
mysql>SELECT UNIX_TIMESTAMP();
-> 1447431666 mysql>SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');
-> 1447431619 mysql>SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');
-> 1447431619.012
UNIX_TIMESTAMP()
TIMESTAMP
UNIX_TIMESTAMP()
TIMESTAMP
'2038-01-19 03:14:07.999999'
UNIX_TIMESTAMP()
FROM_UNIXTIME()
TIMESTAMP
UNIX_TIMESTAMP()
TIMESTAMP
FROM_UNIXTIME()
TIMESTAMP
TIMESTAMP
mysql>SELECT UNIX_TIMESTAMP('2005-03-27 03:00:00');
+---------------------------------------+ | UNIX_TIMESTAMP('2005-03-27 03:00:00') | +---------------------------------------+ | 1111885200 | +---------------------------------------+ mysql>SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00');
+---------------------------------------+ | UNIX_TIMESTAMP('2005-03-27 02:00:00') | +---------------------------------------+ | 1111885200 | +---------------------------------------+ mysql>SELECT FROM_UNIXTIME(1111885200);
+---------------------------+ | FROM_UNIXTIME(1111885200) | +---------------------------+ | 2005-03-27 03:00:00 | +---------------------------+
UNIX_TIMESTAMP()
'YYYY-MM-DD'
mysql> SELECT UTC_DATE(), UTC_DATE() + 0;
-> '2003-08-14', 20030814
'HH:MM:SS'
fsp
MySQL的> SELECT UTC_TIME(), UTC_TIME() + 0;
- >“18:07:53 ',180753.000000
UTC_TIMESTAMP
UTC_TIMESTAMP([
fsp
])
'YYYY-MM-DD HH:MM:SS'
fsp
MySQL的> SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 0;
- >“2003-08-14 18:08:04 ',20030814180804.000000
date
WEEK()
53
53
mode
default_week_format
mode
mode
mysql>SELECT WEEK('2008-02-20');
-> 7 mysql>SELECT WEEK('2008-02-20',0);
-> 7 mysql>SELECT WEEK('2008-02-20',1);
-> 8 mysql>SELECT WEEK('2008-12-31',1);
-> 53
0
3
7
mode
MySQL的> SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
> 2000, 0
WEEK()
WEEK()
WEEK()
0
5
mode
MySQL的> SELECT WEEK('2000-01-01',2);
> 52
YEARWEEK()
MySQL的> SELECT YEARWEEK('2000-01-01');
-> 199952mysql>SELECT MID(YEARWEEK('2000-01-01'),5,2);
> 52
date
= Monday,1
= Tuesday, …
= Sunday).
mysql>SELECT WEEKDAY('2008-02-03 22:23:00');
-> 6 mysql>SELECT WEEKDAY('2007-11-06');
-> 1
1
WEEKOFYEAR()
WEEK(
date
,3)
MySQL的> SELECT WEEKOFYEAR('2008-02-20');
-> 8
date
9999
mysql> SELECT YEAR('1987-01-01');
-> 1987
YEARWEEK(
date
)YEARWEEK(
date
,mode
)
mode
mode
WEEK()
mode
WEEK()
default_week_format
YEARWEEK()
MySQL的> SELECT YEARWEEK('1987-01-01');
> 198652
DATE
DATETIME
MATCH
(
col1
,col2
,...)
AGAINST (expr
[search_modifier
])
search_modifier:
{在查询扩展|布尔模式|查询扩展的自然语言模式自然语言模式| }
FULLTEXT
InnoDB
MyISAM
CHAR
VARCHAR
TEXT
MySQL
FULLTEXT
CREATE TABLE
ALTER TABLE
CREATE INDEX
FULLTEXT
MATCH() ... AGAINST
MATCH()
IN NATURAL LANGUAGE MODE
IN BOOLEAN MODE
IN NATURAL LANGUAGE MODE WITH
QUERY EXPANSION
FULLTEXT
InnoDB
MyISAM
IN NATURAL LANGUAGE
MODE
MATCH()
FULLTEXT
MATCH()
MATCH()
MySQL的> CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
查询行,0行受影响(0.08秒)MySQL > INSERT INTO articles (title,body) VALUES
('MySQL Tutorial','DBMS stands for DataBase ...'),
('How To Use MySQL Well','After you went through a ...'),
('Optimizing MySQL','In this tutorial we will show ...'),
('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
('MySQL vs. YourSQL','In the following database comparison ...'),
('MySQL Security','When configured properly, MySQL ...');
查询行,6行受影响(0.01秒)记录:6份:0警告:0mysql > SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
---- ------------------- ------------------------------------------ | ID |标题|体| ---- ------------------- ------------------------------------------ | 1 | MYSQL教程| DBMS是数据库…| | 5 | MySQL与yoursql |以下数据库的比较…| ---- ------------------- ------------------------------------------ 2行集(0秒)
utf8mb4
utf8mb4_bin
MATCH()
mysql>SELECT COUNT(*) FROM articles
WHERE MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
+----------+ | COUNT(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)
mysql>SELECT
COUNT(IF(MATCH (title,body) AGAINST ('database' IN NATURAL LANGUAGE MODE), 1, NULL))
AS count
FROM articles;
+-------+ | count | +-------+ | 2 | +-------+ 1 row in set (0.03 sec)
WHERE
MATCH()
MATCH()
body
FULLTEXT
body
MATCH()
MATCH()
SELECT
ORDER BY
MySQL的> SELECT id, MATCH (title,body)
AGAINST ('Tutorial' IN NATURAL LANGUAGE MODE) AS score
FROM articles;
---- --------------------- | ID |评分| ---- --------------------- | 1 | 0.2276446968317031 | | 2 | 0 | | 3 | 0.2276446968317031 | | 4 | 0 | | 5 | 0 | | 6 | 0 | ---- --------------------- 6行集(0秒)
MATCH()
SELECT
MATCH()
MySQL的> SELECT id, body, MATCH (title,body) AGAINST
('Security implications of running MySQL as root'
IN NATURAL LANGUAGE MODE) AS score
FROM articles WHERE MATCH (title,body) AGAINST
('Security implications of running MySQL as root'
IN NATURAL LANGUAGE MODE);
---- ------------------------------------- ----------------- | ID |体|评分| ---- ------------------------------------- ----------------- | 4 | 1。不要跑mysqld为根。2。…| 1.5219271183014 | | 6 |当正确配置,MySQL…| 1.3114095926285 | ---- ------------------------------------- ----------------- 2行集(0秒)
"
FULLTEXT
"test, phrase"
FULLTEXT
aaa'bbb
FULLTEXT
aaa'bbb
FULLTEXT
,
FULLTEXT
FULLTEXT
plugin/fulltext
InnoDB
innodb_ft_min_token_size
ft_min_word_len
FULLTEXT
ngram_token_size
InnoDB
innodb_ft_enable_stopword
innodb_ft_server_stopword_table
innodb_ft_user_stopword_table
ft_stopword_file
MyISAM
articles
mysql>SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('MySQL' IN NATURAL LANGUAGE MODE);
Empty set (0.00 sec)
InnoDB
InnoDB
IN BOOLEAN MODE
-
mysql>SELECT * FROM articles WHERE MATCH (title,body)
AGAINST ('+MySQL -YourSQL' IN BOOLEAN MODE);
+----+-----------------------+-------------------------------------+ | id | title | body | +----+-----------------------+-------------------------------------+ | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 2 | How To Use MySQL Well | After you went through a ... | | 3 | Optimizing MySQL | In this tutorial we will show ... | | 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | | 6 | MySQL Security | When configured properly, MySQL ... | +----+-----------------------+-------------------------------------+
+
-
OR
InnoDB
MATCH()
FULLTEXT
FULLTEXT
innodb_ft_min_token_size
innodb_ft_max_token_size
ft_min_word_len
ft_max_word_len
FULLTEXT
ngram_token_size
innodb_ft_enable_stopword
innodb_ft_server_stopword_table
innodb_ft_user_stopword_table
ft_stopword_file
InnoDB
InnoDB
'+apple'
InnoDB
InnoDB
'+-'
InnoDB
@
MyISAM
+
InnoDB
-
InnoDB
-
+
MATCH() ...
AGAINST()
@
distance
InnoDB
distance
> <
>
<
( )
~
-
*
*
innodb_ft_min_token_size
ft_min_word_len
FULLTEXT
'+
word
+the*'word
"
"
FULLTEXT
"test,
phrase"
'apple banana'
'+apple +juice'
'+apple macintosh'
'+apple -macintosh'
'+apple ~macintosh'
'+apple
-macintosh'
'+apple +(>turnover <strudel)'
'apple*'
'"some words"'
"
InnoDB
InnoDB
MyISAM
InnoDB
TF-IDF
TF
total_records
${IDF} = log10( ${total_records} / ${matching_records} )
${TF} * ${IDF}
TF
${rank} = ${TF} * ${IDF} * ${IDF}
mysql> CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT, FULLTEXT (title,body) ) ENGINE=InnoDB; Query OK, 0 rows affected (1.04 sec) mysql> INSERT INTO articles (title,body) VALUES ('MySQL Tutorial','This database tutorial ...'), ("How To Use MySQL",'After you went through a ...'), ('Optimizing Your Database','In this database tutorial ...'), ('MySQL vs. YourSQL','When comparing databases ...'), ('MySQL Security','When configured properly, MySQL ...'), ('Database, Database, Database','database database database'), ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), ('MySQL Full-Text Indexes', 'MySQL fulltext indexes use a ..'); Query OK, 8 rows affected (0.06 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql> SELECT id, title, body, MATCH (title,body) AGAINST ('database' IN BOOLEAN MODE) AS score FROM articles ORDER BY score DESC; +----+------------------------------+-------------------------------------+---------------------+ | id | title | body | score | +----+------------------------------+-------------------------------------+---------------------+ | 6 | Database, Database, Database | database database database | 1.0886961221694946 | | 3 | Optimizing Your Database | In this database tutorial ... | 0.36289870738983154 | | 1 | MySQL Tutorial | This database tutorial ... | 0.18144935369491577 | | 2 | How To Use MySQL | After you went through a ... | 0 | | 4 | MySQL vs. YourSQL | When comparing databases ... | 0 | | 5 | MySQL Security | When configured properly, MySQL ... | 0 | | 7 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | 0 | | 8 | MySQL Full-Text Indexes | MySQL fulltext indexes use a .. | 0 | +----+------------------------------+-------------------------------------+---------------------+ 8 rows in set (0.00 sec)
id 6
TF
id 6
${IDF} = log10( 8 / 3 ) = 0.42596873216370745
TF
${rank} = ${TF} * ${IDF} * ${IDF}
mysql> SELECT 6*log10(8/3)*log10(8/3); +-------------------------+ | 6*log10(8/3)*log10(8/3) | +-------------------------+ | 1.088696164686938 | +-------------------------+ 1 row in set (0.00 sec)
SELECT ... MATCH ...
AGAINST
1.088696164686938
articles
${rank} = ${TF} * ${IDF} * ${IDF} + ${TF} * ${IDF} * ${IDF}
mysql> SELECT id, title, body, MATCH (title,body) AGAINST ('mysql tutorial' IN BOOLEAN MODE) AS score FROM articles ORDER BY score DESC; +----+------------------------------+-------------------------------------+----------------------+ | id | title | body | score | +----+------------------------------+-------------------------------------+----------------------+ | 1 | MySQL Tutorial | This database tutorial ... | 0.7405621409416199 | | 3 | Optimizing Your Database | In this database tutorial ... | 0.3624762296676636 | | 5 | MySQL Security | When configured properly, MySQL ... | 0.031219376251101494 | | 8 | MySQL Full-Text Indexes | MySQL fulltext indexes use a .. | 0.031219376251101494 | | 2 | How To Use MySQL | After you went through a ... | 0.015609688125550747 | | 4 | MySQL vs. YourSQL | When comparing databases ... | 0.015609688125550747 | | 7 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | 0.015609688125550747 | | 6 | Database, Database, Database | database database database | 0 | +----+------------------------------+-------------------------------------+----------------------+ 8 rows in set (0.00 sec)
id 8
MySQL >选择(1×log10(8 / 6)×log10(8 / 6))(2×log10(8 / 2)×log10(8 / 2));------------------------------------------------------- |(1×log10(8 / 6)×log10(8 / 6))(2×log10(8/2)* log10(8 / 2))| ------------------------------------------------------- | 0.7405621541938003 | ------------------------------------------------------- 1行集(0秒)
SELECT ... MATCH ... AGAINST
WITH QUERY
EXPANSION
mysql>SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('database' IN NATURAL LANGUAGE MODE);
+----+-------------------+------------------------------------------+ | id | title | body | +----+-------------------+------------------------------------------+ | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 5 | MySQL vs. YourSQL | In the following database comparison ... | +----+-------------------+------------------------------------------+ 2 rows in set (0.00 sec) mysql>SELECT * FROM articles
WHERE MATCH (title,body)
AGAINST ('database' WITH QUERY EXPANSION);
+----+-----------------------+------------------------------------------+ | id | title | body | +----+-----------------------+------------------------------------------+ | 5 | MySQL vs. YourSQL | In the following database comparison ... | | 1 | MySQL Tutorial | DBMS stands for DataBase ... | | 3 | Optimizing MySQL | In this tutorial we will show ... | | 6 | MySQL Security | When configured properly, MySQL ... | | 2 | How To Use MySQL Well | After you went through a ... | | 4 | 1001 MySQL Tricks | 1. Never run mysqld as root. 2. ... | +----+-----------------------+------------------------------------------+ 6 rows in set (0.00 sec)
character_set_server
collation_server
character_set_server
collation_server
utf8mb4_0900_ai_ci
utf8mb4_bin
InnoDB
InnoDB
INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD
MySQL >选择*从information_schema.innodb_ft_default_stopword;------- |价值| ------- |一| |约| |一| |是| |作为| |在| |是| |通过| | COM | | de | | EN | |为| |从| |如何| |我| |在| |是| |它| | La | |的| |在| |或| |,| |的| |这| |到| |是| |什么| |当| |哪里| |谁| |将| |与| |和| |的| | WWW | ------- 36行集(0秒)
InnoDB
INNODB_FT_DEFAULT_STOPWORD
innodb_ft_server_stopword_table
db_name
table_name
VARCHAR
InnoDB
-- Create a new stopword tablemysql> CREATE TABLE my_stopwords(value VARCHAR(30)) ENGINE = INNODB;Query OK, 0 rows affected (0.01 sec)-- Insert stopwords (for simplicity, a single stopword is used in this example)mysql> INSERT INTO my_stopwords(value) VALUES ('Ishmael');Query OK, 1 row affected (0.00 sec)-- Create the tablemysql> CREATE TABLE opening_lines (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,opening_line TEXT(500),author VARCHAR(200),title VARCHAR(200)) ENGINE=InnoDB;Query OK, 0 rows affected (0.01 sec)-- Insert data into the tablemysql> INSERT INTO opening_lines(opening_line,author,title) VALUES('Call me Ishmael.','Herman Melville','Moby-Dick'),('A screaming comes across the sky.','Thomas Pynchon','Gravity\'s Rainbow'),('I am an invisible man.','Ralph Ellison','Invisible Man'),('Where now? Who now? When now?','Samuel Beckett','The Unnamable'),('It was love at first sight.','Joseph Heller','Catch-22'),('All this happened, more or less.','Kurt Vonnegut','Slaughterhouse-Five'),('Mrs. Dalloway said she would buy the flowers herself.','Virginia Woolf','Mrs. Dalloway'),('It was a pleasure to burn.','Ray Bradbury','Fahrenheit 451');Query OK, 8 rows affected (0.00 sec)Records: 8 Duplicates: 0 Warnings: 0-- Set the innodb_ft_server_stopword_table option to the new stopword tablemysql> SET GLOBAL innodb_ft_server_stopword_table = 'test/my_stopwords';Query OK, 0 rows affected (0.00 sec)-- Create the full-text index (which rebuilds the table if no FTS_DOC_ID column is defined)mysql> CREATE FULLTEXT INDEX idx ON opening_lines(opening_line);Query OK, 0 rows affected, 1 warning (1.17 sec)Records: 0 Duplicates: 0 Warnings: 1
INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE
InnoDB
innodb_ft_max_token_size
innodb_ft_min_token_size
ngram_token_size
mysql> SET GLOBAL innodb_ft_aux_table='test/opening_lines';Query OK, 0 rows affected (0.00 sec)mysql> SELECT word FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_TABLE LIMIT 15;+-----------+| word |+-----------+| across || all || burn || buy || call || comes || dalloway || first || flowers || happened || herself || invisible || less || love || man |+-----------+15 rows in set (0.00 sec)
innodb_ft_user_stopword_table
latin1
ucs2
utf16le
ft_stopword_file
FULLTEXT
_
MyISAM
a's able about above according accordingly across actually after afterwards again against ain't all allow allows almost alone along already also although always am among amongst an and another any anybody anyhow anyone anything anyway anyways anywhere apart appear appreciate appropriate are aren't around as aside ask asking associated at available away awfully be became because become becomes becoming been before beforehand behind being believe below beside besides best better between beyond both brief but by c'mon c's came can can't cannot cant cause causes certain certainly changes clearly co com come comes concerning consequently consider considering contain containing contains corresponding could couldn't course currently definitely described despite did didn't different do does doesn't doing don't done down downwards during each edu eg eight either else elsewhere enough entirely especially et etc even ever every everybody everyone everything everywhere ex exactly example except far few fifth first five followed following follows for former formerly forth four from further furthermore get gets getting given gives go goes going gone got gotten greetings had hadn't happens hardly has hasn't have haven't having he he's hello help hence her here here's hereafter hereby herein hereupon hers herself hi him himself his hither hopefully how howbeit however i'd i'll i'm i've ie if ignored immediate in inasmuch inc indeed indicate indicated indicates inner insofar instead into inward is isn't it it'd it'll it's its itself just keep keeps kept know known knows last lately later latter latterly least less lest let let's like liked likely little look looking looks ltd mainly many may maybe me mean meanwhile merely might more moreover most mostly much must my myself name namely nd near nearly necessary need needs neither never nevertheless new next nine no nobody non none noone nor normally not nothing novel now nowhere obviously of off often oh ok okay old on once one ones only onto or other others otherwise ought our ours ourselves out outside over overall own particular particularly per perhaps placed please plus possible presumably probably provides que quite qv rather rd re really reasonably regarding regardless regards relatively respectively right said same saw say saying says second secondly see seeing seem seemed seeming seems seen self selves sensible sent serious seriously seven several shall she should shouldn't since six so some somebody somehow someone something sometime sometimes somewhat somewhere soon sorry specified specify specifying still sub such sup sure t's take taken tell tends th than thank thanks thanx that that's thats the their theirs them themselves then thence there there's thereafter thereby therefore therein theres thereupon these they they'd they'll they're they've think third this thorough thoroughly those though three through throughout thru thus to together too took toward towards tried tries truly try trying twice two un under unfortunately unless unlikely until unto up upon us use used useful uses using usually value various very via viz vs want wants was wasn't way we we'd we'll we're we've welcome well went were weren't what what's whatever when whence whenever where where's whereafter whereas whereby wherein whereupon wherever whether which while whither who who's whoever whole whom whose why will willing wish with within without won't wonder would wouldn't yes yet you you'd you'll you're you've your yours yourself yourselves zero
utf8
FULLTEXT
IN BOOLEAN MODE
utf8
ucs2
utf16le
InnoDB
FULLTEXT
MATCH()
MATCH()
MyISAM
AGAINST()
FULLTEXT
InnoDB
INSERT
UPDATE
DELETE
FULLTEXT
innodb_ft_min_token_size
innodb_ft_max_token_size
ft_min_word_len
ft_max_word_len
FULLTEXT
ngram_token_size
FULLTEXT
[mysqld]innodb_ft_min_token_size=2ft_min_word_len=2
FULLTEXT
MyISAM
MyISAM
#define GWS_IN_USE GWS_PROB
#define GWS_IN_USE GWS_FREQ
MATCH()
MyISAM
ft_boolean_syntax
SYSTEM_VARIABLES_ADMIN
SUPER
FULLTEXT
storage/innobase/handler/ha_innodb.cc
storage/myisam/ftdefs.h
true_word_char()
'-'
true_word_char()
<ctype><map>
FULLTEXT
<ctype><map>
innodb_ft_min_token_size
innodb_ft_max_token_size
innodb_ft_server_stopword_table
innodb_ft_user_stopword_table
innodb_ft_enable_stopword
ngram_token_size
innodb_ft_min_token_size
innodb_ft_max_token_size
ngram_token_size
FULLTEXT
ALTER TABLE
ADD INDEX
OPTIMIZE TABLE
innodb_optimize_fulltext_only
mysql> set GLOBAL innodb_optimize_fulltext_only=ON; Query OK, 0 rows affected (0.01 sec) mysql> OPTIMIZE TABLE opening_lines; +--------------------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +--------------------+----------+----------+----------+ | test.opening_lines | optimize | status | OK | +--------------------+----------+----------+----------+ 1 row in set (0.01 sec)
innodb_ft_num_word_optimize
OPTIMIZE TABLE
OPTIMIZE
TABLE
OPTIMIZE TABLE
OPTIMIZE TABLE
ft_min_word_len
ft_max_word_len
ft_stopword_file
FULLTEXT
QUICK
MySQL的> REPAIR TABLE
tbl_name
QUICK;
ALTER TABLE
FULLTEXT
MyISAM
MyISAM
ft_min_word_len
ft_max_word_len
ft_stopword_file
myisamchk --recover --ft_min_word_len=3 tbl_name
.MYI
[mysqld]
[mysqld] ft_min_word_len=3 [myisamchk] ft_min_word_len=3
MyISAM
REPAIR TABLE
ANALYZE TABLE
OPTIMIZE TABLE
ALTER TABLE
latin1_swedish_ci
Index.xml
<charset name="latin1">...<collation name="latin1_fulltext_ci" id="1000"/></charset>
latin1.xml
<collation name="latin1_fulltext_ci"> <map> 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49 44 4E 4F 4F 4F 4F 5D D7 D8 55 55 55 59 59 DE DF 41 41 41 41 5C 5B 5C 43 45 45 45 45 49 49 49 49 44 4E 4F 4F 4F 4F 5D F7 D8 55 55 55 59 59 DE FF </map> </collation>
ctype
'-'
<ctype><map>0020 20 20 20 20 20 20 20 20 28 28 28 28 28 20 2020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2048 10 10 10 10 10 10 10 10 10 10 10 1001 10 1084 84 84 84 84 84 84 84 84 84 10 10 10 10 10 1010 81 81 81 81 81 81 01 01 01 01 01 01 01 01 0101 01 01 01 01 01 01 01 01 01 01 10 10 10 10 1010 82 82 82 82 82 82 02 02 02 02 02 02 02 02 0202 02 02 02 02 02 02 02 02 02 02 10 10 10 10 2010 00 10 02 10 10 10 10 10 10 01 10 01 00 01 0000 10 10 10 10 10 10 10 10 10 02 10 02 00 02 0148 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1010 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1001 01 01 01 01 01 01 01 01 01 01 01 01 01 01 0101 01 01 01 01 01 01 10 01 01 01 01 01 01 01 0202 02 02 02 02 02 02 02 02 02 02 02 02 02 02 0202 02 02 02 02 02 02 10 02 02 02 02 02 02 02 02</map></ctype>
mysql>DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.13 sec) mysql>CREATE TABLE t1 (
a TEXT CHARACTER SET latin1 COLLATE latin1_fulltext_ci,
FULLTEXT INDEX(a)
) ENGINE=InnoDB;
Query OK, 0 rows affected (0.47 sec)
mysql>INSERT INTO t1 VALUEs ('----'),('....'),('abcd');
Query OK, 3 rows affected (0.22 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql>SELECT * FROM t1 WHERE MATCH a AGAINST ('----' IN BOOLEAN MODE);
+------+ | a | +------+ | ---- | +------+ 1 row in set (0.00 sec)
InnoDB
MyISAM
n
n
n
n=1: 'a', 'b', 'c', 'd'n=2: 'ab', 'bc', 'cd'n=3: 'abc', 'bcd'n=4: 'abcd'
innodb_ft_min_token_size
innodb_ft_max_token_size
ft_min_word_len
ft_max_word_len
ngram_token_size
ngram_token_size
ngram_token_size
ngram_token_size
ngram_token_size
ngram_token_size
mysqld --ngram_token_size=2
[mysqld] ngram_token_size=2
FULLTEXT
innodb_ft_min_token_size
innodb_ft_max_token_size
ft_min_word_len
ft_max_word_len
FULLTEXT
CREATE TABLE
ALTER TABLE
CREATE INDEX
ngram
INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE
mysql> USE test;mysql> CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT, FULLTEXT (title,body) WITH PARSER ngram ) ENGINE=InnoDB CHARACTER SET utf8mb4;mysql> SET NAMES utf8mb4;INSERT INTO articles (title,body) VALUES ('数据库管理','在本教程中我将向你展示如何管理数据库'), ('数据库应用开发','学习开发数据库应用程序'); mysql> SET GLOBAL innodb_ft_aux_table="test/articles";mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE ORDER BY doc_id, position;
FULLTEXT
ALTER TABLE
CREATE INDEX
CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT ) ENGINE=InnoDB CHARACTER SET utf8;ALTER TABLE articles ADD FULLTEXT INDEX ft_index (title,body) WITH PARSER ngram;# Or:CREATE FULLTEXT INDEX ft_index ON articles (title,body) WITH PARSER ngram;
ngram_token_size=2
ngram_token_size
ngram_token_size=2
ngram_token_size=2
FULLTEXT
ngram_token_size=2
ngram_token_size=2
InnoDB
MyISAM
n
n
mecab
mecab
libmecab.so
mecab-ipadic
MYSQL_HOME
mecab
mecab
mecab
mecab
libmecab.dll
mecab-ipadic
MYSQL_HOME
mecab_rc_file
mecabrc
[mysqld] loose-mecab-rc-file=MYSQL_HOME/lib/mecab/etc/mecabrc
loose
mecab_rc_file
mecabrc
InnoDB
innodb_ft_min_token_size
ft_min_word_len
[mysqld]innodb_ft_min_token_size=1
mecabrc
ipadic_euc-jp
ipadic_gb3212
dicdir = /path/to/mysql/lib/mecab/lib/mecab/dic/ipadic_euc-jp
ipadic_gb3212
dicdir=MYSQL_HOME
/ LIB / MEMB / DIC / IPADIC AND gb3212
dicdir
mecab_charset
ipadic_euc-jp
eucjpms
ipadic_sjis
cp932
ipadic_gb3212
utf8mb4
mecab_charset
utf8
mecab_charset
INSTALL PLUGIN
libpluginmecab.so
INSTALL PLUGIN mecab SONAME 'libpluginmecab.so';
SHOW PLUGINS
MySQL >显示插件;
mecab
FULLTEXT
CREATE TABLE
ALTER TABLE
CREATE INDEX
mecab
INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE
mysql> USE test;mysql> CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT, FULLTEXT (title,body) WITH PARSER mecab ) ENGINE=InnoDB CHARACTER SET utf8;mysql> SET NAMES utf8; mysql> INSERT INTO articles (title,body) VALUES ('データベース管理','このチュートリアルでは、私はどのようにデータベースを管理する方法を紹介します'), ('データベースアプリケーション開発','データベースアプリケーションを開発することを学ぶ');mysql> SET GLOBAL innodb_ft_aux_table="test/articles";mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_INDEX_CACHE ORDER BY doc_id, position;
FULLTEXT
ALTER TABLE
CREATE INDEX
CREATE TABLE articles ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, title VARCHAR(200), body TEXT ) ENGINE=InnoDB CHARACTER SET utf8;ALTER TABLE articles ADD FULLTEXT INDEX ft_index (title,body) WITH PARSER mecab;# Or:CREATE FULLTEXT INDEX ft_index ON articles (title,body) WITH PARSER mecab;
SELECT COUNT(*) FROM articles WHERE MATCH(title,body) AGAINST('データベース管理' IN NATURAL LANGUAGE MODE);
SELECT COUNT(*) FROM articles WHERE MATCH(title,body) AGAINST('データベース管理' IN BOOLEAN MODE);
SELECT COUNT(*) FROM articles WHERE MATCH(title,body) AGAINST('データベース*' IN BOOLEAN MODE);
SELECT COUNT(*) FROM articles WHERE MATCH(title,body) AGAINST('"データベース管理"' IN BOOLEAN MODE);
mecab
yum mecab-devel
apt-get install mecab apt-get install mecab-ipadic
mecab
mecab
mecab-0.996.tar.gz
mecab
zxfv mecab-0.996.tarcd mecab-0.996焦油/ configuremakemake checksumake安装。
mecab-ipadic
焦油zxfv mecab-ipadic-2.7.0-20070801.tarcd mecab-ipadic-2.7.0-20070801 / configuremakesumake安装。
WITH_MECAB
WITH_MECAB
mecab
-DWITH_MECAB=system
WITH_MECAB
-DWITH_MECAB=/path/to/mecab
CONVERT()
CONVERT(expr
USINGtranscoding_name
)
SELECT CONVERT(_latin1'Müller' USING utf8); INSERT INTO utf8_table (utf8_column) SELECT CONVERT(latin1_column USING utf8) FROM latin1_table;
CONVERT()
CAST()
转换( string
,字符[( N
)]字符集 charset_name
铸造() string
焦炭[( N
)]字符集 charset_name
)
SELECT CONVERT('test', CHAR CHARACTER SET utf8); SELECT CAST('test' AS CHAR CHARACTER SET utf8);
CHARACTER SET
charset_name
charset_name
charset_name
charset_name
character_set_connection
collation_connection
COLLATE
CONVERT()
CAST()
选择演员(测试为char字符集utf8)整理utf8_bin;
SELECT CAST('test' AS CHAR CHARACTER SET utf8 COLLATE utf8_bin);
BLOB
CONVERT()
CAST()
LIKE
选择一个像转换( blob_col
使用latin1)从 tbl_name
;
latin1
CONVERT()
选择一个像转换( blob_col
使用latin1)整理latin1_german1_ci从 tbl_name
;
CONVERT()
CAST()
MySQL的> SET @s1 = _latin1 'abc', @s2 = _latin2 'abc';
MySQL的> SELECT @s1 = @s2;
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT)and (latin2_general_ci,IMPLICIT) for operation '='
mysql> SELECT @s1 = CONVERT(@s2 USING latin1);
+---------------------------------+
| @s1 = CONVERT(@s2 USING latin1) |
+---------------------------------+
| 1 |
+---------------------------------+
_latin1
CAST()
CONVERT()
LOWER()
UPPER()
MySQL的> SET @str = BINARY 'New York';
MySQL的> SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));
------------- ------------------------------------ |下(@ STR)|低(转换(@ STR使用utf8mb4))| ------------- ------------------------------------ |纽约|纽约| ------------- ------------------------------------
BINARY
CAST()
CONVERT()
CREATE TABLE ...
SELECT
MySQL的> CREATE TABLE new_table SELECT CAST('2000-01-01' AS DATE) AS c1;
MySQL的> SHOW CREATE TABLE new_table\G
*************************** 1. row *************************** Table: new_tableCreate Table: CREATE TABLE `new_table` ( `c1` date DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
ENUM
ENUM
CHAR
选择 enum_col
从 tbl_name
以铸造( enum_col
焦炭);
CAST()
CONCAT('Date: ',CAST(NOW() AS
DATE))
CAST()
EXTRACT()
DATE_FORMAT()
TIME_FORMAT()
mysql> SELECT 1+'1';
-> 2
mysql>SELECT X'41', X'41'+0;
-> 'A', 65 mysql>SELECT b'1100001', b'1100001'+0;
-> 'a', 97
mysql> SELECT CONCAT('hello you ',2);
-> 'hello you 2'
+
-
SIGNED
mysql>SELECT 1 - 2;
-> -1 mysql>SELECT CAST(1 - 2 AS UNSIGNED);
-> 18446744073709551615 mysql>SELECT CAST(CAST(1 - 2 AS UNSIGNED) AS SIGNED);
-> -1
DECIMAL
MySQL的> SELECT CAST(1 AS UNSIGNED) - 2.0;
> 1
CONVERT()
CAST()
NO_ZERO_DATE
NO_UNSIGNED_SUBTRACTION
BINARY
expr
BINARY
BINARY
BINARY
MySQL的> SELECT 'a' = 'A';
-> 1mysql>SELECT BINARY 'a' = 'A';
-> 0mysql>SELECT 'a' = 'a ';
-> 1mysql>SELECT BINARY 'a' = 'a ';
> 0
BINARY
BINARYexpr
CAST(expr
AS BINARY) CONVERT(expr
USING BINARY)
_binary
MySQL的> SELECT 'a' = 'A';
-> 1mysql>SELECT _binary 'a' = 'A';
> 0
BINARY
BINARY
_bin
utf8_bin
CHAR(10) BINARY CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin
CHARACTER SET binary
CHAR
VARCHAR
TEXT
char(10)字符集binarybinary(10)varchar(10)字符集binaryvarbinary(10)文本字符集binaryblob
CAST()
CONVERT()
CONVERT()
CAST()
CONVERT(
expr
,type
)CONVERT(
expr
USING transcoding_name
)
CONVERT()
CONVERT(
expr
,
type
)CAST(
expr
AS
type
)
CONVERT(... USING ...)
CONVERT()
CONVERT()
'abc'
SELECT CONVERT('abc' USING utf8);
CONVERT()
CAST()
type
type
BINARY[(
N
)]
BINARY
N
N
N
N
N
CHAR[(
N
)]
[charset_info
]
CHAR
N
N
N
N
charset_info
charset_info
CHARACTER SET
charset_name
ASCII
UNICODE
DATE
DATE
DATETIME
DATETIME
DECIMAL[(
M
[,D
])]
DECIMAL
M
D
JSON
JSON
JSON
NCHAR[(
N
)]
CHAR
CHAR
SIGNED [INTEGER]
TIME
TIME
UNSIGNED [INTEGER]
--xml
$@
variable_name
$@myvariable
mysql>SET @xml = '<a><b>X</b><b>Y</b></a>';
Query OK, 0 rows affected (0.00 sec) mysql>SET @i =1, @j = 2;
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @i, ExtractValue(@xml, '//b[$@i]');
+------+--------------------------------+ | @i | ExtractValue(@xml, '//b[$@i]') | +------+--------------------------------+ | 1 | X | +------+--------------------------------+ 1 row in set (0.00 sec) mysql>SELECT @j, ExtractValue(@xml, '//b[$@j]');
+------+--------------------------------+ | @j | ExtractValue(@xml, '//b[$@j]') | +------+--------------------------------+ | 2 | Y | +------+--------------------------------+ 1 row in set (0.00 sec) mysql>SELECT @k, ExtractValue(@xml, '//b[$@k]');
+------+--------------------------------+ | @k | ExtractValue(@xml, '//b[$@k]') | +------+--------------------------------+ | NULL | | +------+--------------------------------+ 1 row in set (0.00 sec)
$
variable_name
mysql>DELIMITER |
mysql>CREATE PROCEDURE myproc ()
->BEGIN
->DECLARE i INT DEFAULT 1;
->DECLARE xml VARCHAR(25) DEFAULT '<a>X</a><a>Y</a><a>Z</a>';
-> ->WHILE i < 4 DO
->SELECT xml, i, ExtractValue(xml, '//a[$i]');
->SET i = i+1;
->END WHILE;
->END |
Query OK, 0 rows affected (0.01 sec) mysql>DELIMITER ;
mysql>CALL myproc();
+--------------------------+---+------------------------------+ | xml | i | ExtractValue(xml, '//a[$i]') | +--------------------------+---+------------------------------+ | <a>X</a><a>Y</a><a>Z</a> | 1 | X | +--------------------------+---+------------------------------+ 1 row in set (0.00 sec) +--------------------------+---+------------------------------+ | xml | i | ExtractValue(xml, '//a[$i]') | +--------------------------+---+------------------------------+ | <a>X</a><a>Y</a><a>Z</a> | 2 | Y | +--------------------------+---+------------------------------+ 1 row in set (0.01 sec) +--------------------------+---+------------------------------+ | xml | i | ExtractValue(xml, '//a[$i]') | +--------------------------+---+------------------------------+ | <a>X</a><a>Y</a><a>Z</a> | 3 | Z | +--------------------------+---+------------------------------+ 1 row in set (0.01 sec)
ExtractValue(
xml_frag
,
xpath_expr
)
ExtractValue()
xml_frag
xpath_expr
CDATA
xpath_expr
ExtractValue('<a><b>Sakila</b></a>',
'/a/b')
ExtractValue('<a><b>Sakila</b></a>',
'/a/b/text()')
/text()
xpath_expr
xml_frag
xml_frag
mysql>SELECT ExtractValue('<a><b/></a>', '/a/b');
+-------------------------------------+ | ExtractValue('<a><b/></a>', '/a/b') | +-------------------------------------+ | | +-------------------------------------+ 1 row in set (0.00 sec) mysql>SELECT ExtractValue('<a><c/></a>', '/a/b');
+-------------------------------------+ | ExtractValue('<a><c/></a>', '/a/b') | +-------------------------------------+ | | +-------------------------------------+ 1 row in set (0.00 sec)
mysql>SELECT ExtractValue('<a><b/></a>', 'count(/a/b)');
+-------------------------------------+ | ExtractValue('<a><b/></a>', 'count(/a/b)') | +-------------------------------------+ | 1 | +-------------------------------------+ 1 row in set (0.00 sec) mysql>SELECT ExtractValue('<a><c/></a>', 'count(/a/b)');
+-------------------------------------+ | ExtractValue('<a><c/></a>', 'count(/a/b)') | +-------------------------------------+ | 0 | +-------------------------------------+ 1 row in set (0.01 sec)
ExtractValue()
val1
MySQL的> SELECT
-> ExtractValue('<a>ccc<b>ddd</b></a>', '/a') AS val1,
-> ExtractValue('<a>ccc<b>ddd</b></a>', '/a/b') AS val2,
-> ExtractValue('<a>ccc<b>ddd</b></a>', '//b') AS val3,
-> ExtractValue('<a>ccc<b>ddd</b></a>', '/b') AS val4,
-> ExtractValue('<a>ccc<b>ddd</b><b>eee</b></a>', '//b') AS val5;
????????????--------- | val1 | val2 | val3 | val4 | val5 | ------?????????--------- | CCC | | DDD DDD DDD | | EEE????????????--------- |
contains()
CONCAT()
NULL
xml_frag
MySQL的> SELECT ExtractValue('<a>c</a><b', '//a');
+-----------------------------------+| ExtractValue('<a>c</a><b', '//a') |+-----------------------------------+| NULL |+-----------------------------------+1 row in set, 1 warning (0.00 sec)mysql>SHOW WARNINGS\G
*************************** 1. row *************************** Level: Warning Code: 1525Message: Incorrect XML value: 'parse error at line 1 pos 11: END-OF-INPUT unexpected ('>' wanted)'1 row in set (0.00 sec)mysql>SELECT ExtractValue('<a>c</a><b/>', '//a');
+-------------------------------------+| ExtractValue('<a>c</a><b/>', '//a') |+-------------------------------------+| c |+-------------------------------------+1 row in set (0.00 sec)
UpdateXML(
xml_target
,
xpath_expr
,
new_xml
)
xml_target
new_xml
xml_target
xpath_expr
xpath_expr
xml_target
MySQL的> SELECT
-> UpdateXML('<a><b>ccc</b><d></d></a>', '/a', '<e>fff</e>') AS val1,
-> UpdateXML('<a><b>ccc</b><d></d></a>', '/b', '<e>fff</e>') AS val2,
-> UpdateXML('<a><b>ccc</b><d></d></a>', '//b', '<e>fff</e>') AS val3,
-> UpdateXML('<a><b>ccc</b><d></d></a>', '/a/d', '<e>fff</e>') AS val4,
-> UpdateXML('<a><d></d><b>ccc</b><d></d></a>', '/a/d', '<e>fff</e>') AS val5
-> \G
*************************** 1. row ***************************val1: <e>fff</e>val2: <a><b>ccc</b><d></d></a>val3: <a><e>fff</e><d></d></a>val4: <a><b>ccc</b><e>fff</e></a>val5: <a><d></d><b>ccc</b><d></d></a>
/
tag
<
tag
/><
tag
/a
<a><b/></a>
a
<b><a/></b>
/
tag1
/tag2
<
tag2
/><
tag1
<
tag1
/a/b
b
<a><b/></a>
a
<b><a/></b>
b
<a><c><b/></c></a>
b
a
a
/a/b/c
c
<a><b><c/></b></a>
//
tag
<
tag
>
//a
a
<a><b><c/></b></a>
<c><a><b/></a></b>
<c><b><a/></b></c>
//
//a/b
b
<a><b/></a>
<c><a><b/></a></c>
//
tag
tag
tag
MySQL的> SET @xml = '<a><b><c>w</c><b>x</b><d>y</d>z</b></a>';
查询好,为受影响的行(0.001秒)MySQL > SELECT @xml;
+-----------------------------------------+| @xml |+-----------------------------------------+| <a><b><c>w</c><b>x</b><d>y</d>z</b></a> |+-----------------------------------------+1 row in set (0.00 sec)mysql>SELECT ExtractValue(@xml, '//b[1]');
------------------------------ |导致(@ XML,/ / b [1 ]”)| ------------------------------ | X Z | ------------------------------一行集(0.001秒)MySQL > SELECT ExtractValue(@xml, '//b[2]');
------------------------------ |导致(@ XML,/ / B [ 2 ]”)| ------------------------------ | | ------------------------------ 1行集(0.01秒)MySQL > SELECT ExtractValue(@xml, '/descendant-or-self::*/b[1]');
--------------------------------------------------- |导致(@ XML /后裔或自我::* / B [ 1 ]”)| --------------------------------------------------- | X Z | --------------------------------------------------- 1行集(0.06秒)MySQL > SELECT ExtractValue(@xml, '/descendant-or-self::*/b[2]');
--------------------------------------------------- |导致(@ XML /后裔或自我::* / B [ 2 ]”)| --------------------------------------------------- | | --------------------------------------------------- 1行集(0秒)MySQL > SELECT ExtractValue(@xml, '/descendant-or-self::b[1]');
------------------------------------------------- |导致(@ XML /后裔或自我::B [ 1 ]”)| ------------------------------------------------- | Z | ------------------------------------------------- 1行集(0秒)MySQL > SELECT ExtractValue(@xml, '/descendant-or-self::b[2]');
------------------------------------------------- |导致(@ XML /后裔或自我::B [ 2 ]”)| ------------------------------------------------- | X | ------------------------------------------------- 1行集(0秒)
*
/*/b
b
<a><b/></a>
<c><b/></c>
<b><a/></b>
b
b
|
UNION
b
c
tag
[@attribute
="value
"]//b[@id="idB"]
b
<a><b id="idA"/><c/><b id="idB"/></a>
attribute
="value
"attribute
="value
//b[@c="x"][@d="y"]
<b c="x" d="y"/>
|
b
c
//b[@c="23"]|//b[@c="17"]
or
//b[@c="23" or @c="17"]
or
or
'/a/b[@c=@d]'
mysql>SELECT ExtractValue(
->'<a><b c="1">X</b><b c="2">Y</b></a>',
->'a/b'
->) AS result;
+--------+ | result | +--------+ | X Y | +--------+ 1 row in set (0.03 sec)
a/b
d[../@c="1"]
/a/b[@c="1"]/d
mysql>SELECT ExtractValue(
->'<a>
-><b c="1"><d>X</d></b>
-><b c="2"><d>X</d></b>
-></a>',
->'a/b/d[../@c="1"]')
->AS result;
+--------+ | result | +--------+ | X | +--------+ 1 row in set (0.00 sec)
::
axis
::comment()
axis
::text()
axis
::processing-instructions()
axis
::node()
axis
::name
axis
MySQL的> SELECT ExtractValue('<a><b>x</b><c>y</c></a>','/a/child::b');
+-------------------------------------------------------+| ExtractValue('<a><b>x</b><c>y</c></a>','/a/child::b') |+-------------------------------------------------------+| x |+-------------------------------------------------------+1 row in set (0.02 sec)mysql>SELECT ExtractValue('<a><b>x</b><c>y</c></a>','/a/child::*');
+-------------------------------------------------------+| ExtractValue('<a><b>x</b><c>y</c></a>','/a/child::*') |+-------------------------------------------------------+| x y |+-------------------------------------------------------+1 row in set (0.01 sec)
id()
lang()
local-name()
name()
namespace-uri()
normalize-space()
starts-with()
string()
substring-after()
substring-before()
translate()
following-sibling
following
preceding-sibling
preceding
ExtractValue()
UpdateXML()
mysql>SET @xml = '<a>111<b:c>222<d>333</d><e:f>444</e:f></b:c></a>';
Query OK, 0 rows affected (0.00 sec) mysql>SELECT ExtractValue(@xml, '//e:f');
+-----------------------------+ | ExtractValue(@xml, '//e:f') | +-----------------------------+ | 444 | +-----------------------------+ 1 row in set (0.00 sec) mysql>SELECT UpdateXML(@xml, '//b:c', '<g:h>555</g:h>');
+--------------------------------------------+ | UpdateXML(@xml, '//b:c', '<g:h>555</g:h>') | +--------------------------------------------+ | <a>111<g:h>555</g:h></a> | +--------------------------------------------+ 1 row in set (0.00 sec)
namespace-uri()
ExtractValue()
UpdateXML()
MySQL的> SELECT ExtractValue('<a>c</a><b/>', '/&a');
错误1105(hy000):XPath语法错误:'和'
xml_frag
mysql>SELECT ExtractValue('<a>c</a><b', '//a');
+-----------------------------------+ | ExtractValue('<a>c</a><b', '//a') | +-----------------------------------+ | NULL | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql>SHOW WARNINGS\G
*************************** 1. row *************************** Level: Warning Code: 1525 Message: Incorrect XML value: 'parse error at line 1 pos 11: END-OF-INPUT unexpected ('>' wanted)' 1 row in set (0.00 sec) mysql>SELECT ExtractValue('<a>c</a><b/>', '//a');
+-------------------------------------+ | ExtractValue('<a>c</a><b/>', '//a') | +-------------------------------------+ | c | +-------------------------------------+ 1 row in set (0.00 sec)
UpdateXML()
//user[login/text()='neapolitan' and password/text()='1c3cr34m']/attribute::id
SELECT id FROM users WHERE login='neapolitan' AND password='1c3cr34m';
<?php $file = "users.xml"; $login = $POST["login"]; $password = $POST["password"]; $xpath = "//user[login/text()=$login and password/text()=$password]/attribute::id"; if( file_exists($file) ) { $xml = simplexml_load_file($file); if($result = $xml->xpath($xpath)) echo "You are now logged in as user $result[0]."; else echo "Invalid login name or password."; } else exit("Failed to open $file."); ?>
' or 1=1
//user[login/text()='' or 1=1 and password/text()='' or 1=1]/attribute::id
true
user
/ / /属性:用户ID
$xpath
$xpath = "//user[login/text()='$login' and password/text()='$password']/attribute::id";
ExtractValue()
MySQL的> SELECT ExtractValue(
-> LOAD_FILE('users.xml'),
-> '//user[login/text()="" or 1=1 and password/text()="" or 1=1]/attribute::id'
-> ) AS id;
------------------------------- | ID | ------------------------------- | 00327 13579 02403 42354 28570 | ------------------------------- 1行集(0.01秒)
ExtractValue()
mysql>SELECT @id = ExtractValue(
->LOAD_FILE('users.xml'),
->'//user[login/text()="" or 1=1 and password/text()="" or 1=1]/attribute::id'
->);
Query OK, 0 rows affected (0.00 sec) mysql>SELECT IF(
->INSTR(@id, ' ') = 0,
->@id,
->'Unable to retrieve user ID')
->AS singleID;
+----------------------------+ | singleID | +----------------------------+ | Unable to retrieve user ID | +----------------------------+ 1 row in set (0.00 sec)
BIT_COUNT()
BIT_AND()
BIT_OR()
BIT_XOR()
&
|
^
~
<<
>>
BIT_AND()
BIT_OR()
BIT_XOR()
BIGINT
BIGINT
BIGINT
BIGINT
BINARY
VARBINARY
BLOB
BIGINT
BIGINT
BIGINT
mysql> SELECT 127 | 128, 128 << 2, BIT_COUNT(15);
+-----------+----------+---------------+
| 127 | 128 | 128 << 2 | BIT_COUNT(15) |
+-----------+----------+---------------+
| 255 | 512 | 4 |
+-----------+----------+---------------+
'127'
mysql> SELECT '127' | '128', '128' << 2, BIT_COUNT('15');
+---------------+------------+-----------------+
| '127' | '128' | '128' << 2 | BIT_COUNT('15') |
+---------------+------------+-----------------+
| 255 | 512 | 4 |
+---------------+------------+-----------------+
mysql> SELECT X'7F' | X'80', X'80' << 2, BIT_COUNT(X'0F');
+---------------+------------+------------------+
| X'7F' | X'80' | X'80' << 2 | BIT_COUNT(X'0F') |
+---------------+------------+------------------+
| 255 | 512 | 4 |
+---------------+------------+------------------+
UUID: 6ccd780c-baba-1026-9564-5b8c656024db IPv6: fe80::219:d1ff:fe91:1a72
UUID_TO_BIN()
INET6_ATON()
BINARY(16)
mysql>SELECT HEX(UUID_TO_BIN('6ccd780c-baba-1026-9564-5b8c656024db'));
+----------------------------------------------------------+ | HEX(UUID_TO_BIN('6ccd780c-baba-1026-9564-5b8c656024db')) | +----------------------------------------------------------+ | 6CCD780CBABA102695645B8C656024DB | +----------------------------------------------------------+ mysql>SELECT HEX(INET6_ATON('fe80::219:d1ff:fe91:1a72'));
+---------------------------------------------+ | HEX(INET6_ATON('fe80::219:d1ff:fe91:1a72')) | +---------------------------------------------+ | FE800000000000000219D1FFFE911A72 | +---------------------------------------------+
BINARY
VARBINARY
BLOB
_binary
mysql> SELECT X'40' | X'01', b'11110001' & b'01001111';
+---------------+---------------------------+
| X'40' | X'01' | b'11110001' & b'01001111' |
+---------------+---------------------------+
| 65 | 65 |
+---------------+---------------------------+
_binary
MySQL的> SELECT _binary X'40' | X'01', b'11110001' & _binary b'01001111';
----------------------- ----------------------------------- | _binary x 40的| x 01的| B '11110001”和_binary B '01001111”| ----------------------- ----------------------------------- |一|一| ----------------------- -----------------------------------
A
mysql> SELECT _binary X'4040404040404040' | X'0102030405060708';
+---------------------------------------------------+
| _binary X'4040404040404040' | X'0102030405060708' |
+---------------------------------------------------+
| ABCDEFGH |
+---------------------------------------------------+
_binaryliteral
BINARYliteral
CAST(literal
AS BINARY)
mysql>SET @v1 = X'40', @v2 = X'01', @v3 = b'11110001', @v4 = b'01001111';
mysql>SELECT @v1 | @v2, @v3 & @v4;
+-----------+-----------+ | @v1 | @v2 | @v3 & @v4 | +-----------+-----------+ | A | A | +-----------+-----------+
ER_INVALID_BITWISE_OPERANDS_SIZE
MySQL的> SELECT _binary X'40' | X'0001';
错误3513(hy000):bitwiseoperators二进制操作数的长度必须相等
mysql>SELECT _binary X'0040' | X'0001';
+---------------------------+ | _binary X'0040' | X'0001' | +---------------------------+ | A | +---------------------------+ mysql>SELECT _binary X'40' | X'01';
+-----------------------+ | _binary X'40' | X'01' | +-----------------------+ | A | +-----------------------+
LPAD()
RPAD()
SUBSTR()
CAST()
mysql>SELECT LPAD(X'40', 2, X'00') | X'0001';
+---------------------------------+ | LPAD(X'40', 2, X'00') | X'0001' | +---------------------------------+ | A | +---------------------------------+ mysql>SELECT X'40' | SUBSTR(X'0001', 2, 1);
+-------------------------------+ | X'40' | SUBSTR(X'0001', 2, 1) | +-------------------------------+ | A | +-------------------------------+
mysql>SET @uuid = UUID_TO_BIN('6ccd780c-baba-1026-9564-5b8c656024db');
mysql>SELECT HEX(@uuid);
+----------------------------------+ | HEX(@uuid) | +----------------------------------+ | 6CCD780CBABA102695645B8C656024DB | +----------------------------------+
mysql>SET @ts_mask = CAST(X'FFFFFFFFFFFFFFFF' AS BINARY(16));
mysql>SET @node_mask = CAST(X'FFFFFFFFFFFF' AS BINARY(16)) >> 80;
mysql>SELECT HEX(@ts_mask);
+----------------------------------+ | HEX(@ts_mask) | +----------------------------------+ | FFFFFFFFFFFFFFFF0000000000000000 | +----------------------------------+ mysql>SELECT HEX(@node_mask);
+----------------------------------+ | HEX(@node_mask) | +----------------------------------+ | 00000000000000000000FFFFFFFFFFFF | +----------------------------------+
CAST(... AS BINARY(16))
SET @ts_mask= RPAD(X'FFFFFFFFFFFFFFFF' , 16, X'00');SET @node_mask = LPAD(X'FFFFFFFFFFFF', 16, X'00') ;
mysql>SELECT HEX(@uuid & @ts_mask) AS 'timestamp part';
+----------------------------------+ | timestamp part | +----------------------------------+ | 6CCD780CBABA10260000000000000000 | +----------------------------------+ mysql>SELECT HEX(@uuid & @node_mask) AS 'node part';
+----------------------------------+ | node part | +----------------------------------+ | 000000000000000000005B8C656024DB | +----------------------------------+
UUID_TO_BIN()
The next example uses bit operations to extract the network and host parts of an IPv6 address. Suppose that the network part has a length of 80 bits. Then the host part has a length of 128 ? 80 = 48 bits. To extract the network and host parts of the address, convert it to a binary string, then use bit operations in binary-string context.
mysql> SET @ip = INET6_ATON('fe80::219:d1ff:fe91:1a72');
mysql> SET @net_len = 80;
::
MySQL的> SELECT HEX(INET6_ATON('::')) AS 'all zeros';
---------------------------------- |全零| ---------------------------------- | 00000000000000000000000000000000 | ----------------------------------
~
MySQL的> SELECT HEX(~INET6_ATON('::')) AS 'all ones';
一| ---------------------------------- |所有---------------------------------- | ffffffffffffffffffffffffffffffff | ----------------------------------
mysql>SET @net_mask = ~INET6_ATON('::') << (128 - @net_len);
mysql>SET @host_mask = ~INET6_ATON('::') >> @net_len;
mysql>SELECT INET6_NTOA(@net_mask) AS 'network mask';
+----------------------------+ | network mask | +----------------------------+ | ffff:ffff:ffff:ffff:ffff:: | +----------------------------+ mysql>SELECT INET6_NTOA(@host_mask) AS 'host mask';
+------------------------+ | host mask | +------------------------+ | ::ffff:255.255.255.255 | +------------------------+
mysql>SET @net_part = @ip & @net_mask;
mysql>SET @host_part = @ip & @host_mask;
mysql>SELECT INET6_NTOA(@net_part) AS 'network part';
+-----------------+ | network part | +-----------------+ | fe80::219:0:0:0 | +-----------------+ mysql>SELECT INET6_NTOA(@host_part) AS 'host part';
+------------------+ | host part | +------------------+ | ::d1ff:fe91:1a72 | +------------------+
~
<<
&
&
|
^
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
mysql> SELECT 64 | 1, X'40' | X'01';
+--------+---------------+
| 64 | 1 | X'40' | X'01' |
+--------+---------------+
| 65 | 65 |
+--------+---------------+
mysql>SELECT _binary X'40' | X'01';
+-----------------------+ | _binary X'40' | X'01' | +-----------------------+ | A | +-----------------------+ mysql>SET @var1 = X'40', @var2 = X'01';
mysql>SELECT @var1 | @var2;
+---------------+ | @var1 | @var2 | +---------------+ | A | +---------------+
~
<<
>>
NULL
mysql> SELECT ~0, 64 << 2, X'40' << 2;
+----------------------+---------+------------+
| ~0 | 64 << 2 | X'40' << 2 |
+----------------------+---------+------------+
| 18446744073709551615 | 256 | 256 |
+----------------------+---------+------------+
mysql>SELECT HEX(_binary X'1111000022220000' >> 16);
+----------------------------------------+ | HEX(_binary X'1111000022220000' >> 16) | +----------------------------------------+ | 0000111100002222 | +----------------------------------------+ mysql>SELECT HEX(_binary X'1111000022220000' << 16);
+----------------------------------------+ | HEX(_binary X'1111000022220000' << 16) | +----------------------------------------+ | 0000222200000000 | +----------------------------------------+ mysql>SET @var1 = X'F0F0F0F0';
mysql>SELECT HEX(~@var1);
+-------------+ | HEX(~@var1) | +-------------+ | 0F0F0F0F | +-------------+
BIT_COUNT()
NULL
MySQL的> SELECT BIT_COUNT(127);
它|位_ count(127)| ---------------- | MySQL > 7 | ---------------- SELECT BIT_COUNT(b'010101'), BIT_COUNT(_binary b'010101');
| ---------------------- _ count()位(位010101)| _计数(_ 010101二进制(3)3)| | ---------------------- | | ---------------------- -------------------
BIT_AND()
BIT_OR()
BIT_XOR()
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
ER_INVALID_BITWISE_AGGREGATE_OPERANDS_SIZE
NULL
BIT_AND()
BIT_OR()
BIT_XOR()
mysql>CREATE TABLE t (group_id INT, a VARBINARY(6));
mysql>INSERT INTO t VALUES (1, NULL);
mysql>INSERT INTO t VALUES (1, NULL);
mysql>INSERT INTO t VALUES (2, NULL);
mysql>INSERT INTO t VALUES (2, X'1234');
mysql>INSERT INTO t VALUES (2, X'FF34');
mysql>SELECT HEX(BIT_AND(a)), HEX(BIT_OR(a)), HEX(BIT_XOR(a))
FROM t GROUP BY group_id;
+-----------------+----------------+-----------------+ | HEX(BIT_AND(a)) | HEX(BIT_OR(a)) | HEX(BIT_XOR(a)) | +-----------------+----------------+-----------------+ | FFFFFFFFFFFF | 000000000000 | 000000000000 | | 1234 | FF34 | ED00 | +-----------------+----------------+-----------------+
NULL
_binary
BINARY
BIGINT
b'0001' | b'0010'X'0008' << 8
NULL
NULL
NULL & NULLNULL >> 4
_binary b'0001' | b'0010' _binary X'0008' << 8 BINARY NULL & NULL BINARY NULL >> 4
NULL
nonliteral_binary
{ & | ^ }binary
binary
{ & | ^ }nonliteral_binary
nonliteral_binary
{ << >> }anything
~nonliteral_binary
AGGR_BIT_FUNC
(nonliteral_binary
)
BIGINT
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
mysql>SELECT 29 | 15;
-> 31 mysql>SELECT _binary X'40404040' | X'01020304';
-> 'ABCD'
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
mysql>SELECT 29 & 15;
-> 13 mysql>SELECT HEX(_binary X'FF' & b'11110000');
-> 'F0'
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
mysql>SELECT 1 ^ 1;
-> 0 mysql>SELECT 1 ^ 0;
-> 1 mysql>SELECT 11 ^ 3;
-> 8 mysql>SELECT HEX(_binary X'FEDC' ^ X'1111');
-> 'EFCD'
BIGINT
NULL
mysql>SELECT 1 << 2;
-> 4 mysql>SELECT HEX(_binary X'00FF00FF00FF' << 8);
-> 'FF00FF00FF00'
BIGINT
NULL
mysql>SELECT 4 >> 2;
-> 1 mysql>SELECT HEX(_binary X'00FF00FF00FF' >> 8);
-> '0000FF00FF00'
NULL
mysql>SELECT 5 & ~1;
-> 4 mysql>SELECT HEX(~X'0000FFFF1111EEEE');
-> 'FFFF0000EEEE1111'
N
NULL
MySQL的> SELECT BIT_COUNT(64), BIT_COUNT(BINARY 64);
-> 1, 7mysql>SELECT BIT_COUNT('64'), BIT_COUNT(_binary '64');
-> 1, 7mysql>SELECT BIT_COUNT(X'40'), BIT_COUNT(_binary X'40');
> 1, 1
AES_DECRYPT() | |
AES_ENCRYPT() | |
ASYMMETRIC_DECRYPT() | |
ASYMMETRIC_DERIVE() | |
ASYMMETRIC_ENCRYPT() | |
ASYMMETRIC_SIGN() | |
ASYMMETRIC_VERIFY() | |
COMPRESS() | |
CREATE_ASYMMETRIC_PRIV_KEY() | |
CREATE_ASYMMETRIC_PUB_KEY() | |
CREATE_DH_PARAMETERS() | |
CREATE_DIGEST() | |
DECODE() | |
DES_DECRYPT() | |
DES_ENCRYPT() | |
ENCODE() | |
ENCRYPT() | |
MD5() | |
PASSWORD() | |
RANDOM_BYTES() | |
SHA1()
| |
SHA2() | |
STATEMENT_DIGEST() | |
STATEMENT_DIGEST_TEXT() | |
UNCOMPRESS() | |
UNCOMPRESSED_LENGTH() | |
VALIDATE_PASSWORD_STRENGTH() |
VARBINARY
BLOB
CHAR
VARCHAR
TEXT
MD5()
SHA()
SHA1()
SHA2()
STATEMENT_DIGEST()
STATEMENT_DIGEST_TEXT()
character_set_connection
collation_connection
MD5()
SHA1()
UNHEX()
BINARY(
N
)N
N
MD5()
SHA1()
SHA2()
N
CHAR
MD5()
CHAR(32)
创建表md5_tbl(md5_val char(32),…);插入md5_tbl(md5_val,…)值(MD5('abcdef '),…);
UNHEX()
BINARY(16)
创建表md5_tbl(md5_val二进制(16),…);插入md5_tbl(md5_val,…)值(unhex(MD5('abcdef ')),…);
SHA2()
AES_DECRYPT(
crypt_str
,key_str
[,init_vector
])
AES_ENCRYPT()
init_vector
AES_DECRYPT()
AES_ENCRYPT(
str
,key_str
[,init_vector
])
AES_ENCRYPT()
AES_DECRYPT()
AES_ENCRYPT()
str
key_str
AES_DECRYPT()
crypt_str
key_str
NULL
str
crypt_str
str
AES_DECRYPT()
crypt_str
*(trunc(16 string_length
16)1)
key_str
插入tvalues(1,aes_encrypt(中,unhex('f3229a0b371ed2d9441b830d21a390c3 ')));
INSERT INTO t VALUES (1,AES_ENCRYPT('text', UNHEX(SHA2('My secret passphrase',512))));
crypt_str
AES_DECRYPT()
AES_DECRYPT()
AES_ENCRYPT()
AES_DECRYPT()
init_vector
block_encryption_mode
init_vector
init_vector
init_vector
init_vector
RANDOM_BYTES(16)
MySQL的> SET block_encryption_mode = 'aes-256-cbc';
MySQL的> SET @key_str = SHA2('My secret passphrase',512);
MySQL的> SET @init_vector = RANDOM_BYTES(16);
MySQL的> SET @crypt_str = AES_ENCRYPT('text',@key_str,@init_vector);
MySQL的> SELECT AES_DECRYPT(@crypt_str,@key_str,@init_vector);
一个多月以前
AES_ENCRYPT()
AES_DECRYPT()
zlib
UNCOMPRESS()
MySQL的> SELECT LENGTH(COMPRESS(REPEAT('a',1000)));
-> 21mysql>SELECT LENGTH(COMPRESS(''));
-> 0mysql>SELECT LENGTH(COMPRESS('a'));
-> 13mysql>SELECT LENGTH(COMPRESS(REPEAT('a',16)));
> 15
AES_ENCRYPT()
AES_DECRYPT()
DES_DECRYPT(
crypt_str
[,key_str
])
AES_ENCRYPT()
AES_DECRYPT()
DES_ENCRYPT(
str
[,{key_num
|key_str
}])
AES_ENCRYPT()
AES_DECRYPT()
AES_ENCRYPT()
AES_DECRYPT()
SHA2()
NULL
MD5()
mysql> SELECT MD5('testing');
-> 'ae2b1fca515949e5d54fb22b8ed95575'
len
len
RANDOM_BYTES()
RANDOM_BYTES()
AES_DECRYPT()
AES_ENCRYPT()
len
RANDOM_BYTES()
NULL
SHA()
SHA1()
mysql> SELECT SHA1('abc');
-> 'a9993e364706816aba3e25717850c26c9cd0d89d'
NULL
mysql> SELECT SHA2('abc', 224);
-> '23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7'
NULL
STATEMENT_DIGEST_TEXT()
max_digest_length
MySQL的> SET @stmt = 'SELECT * FROM mytable WHERE cola = 10 AND colb = 20';
MySQL的> SELECT STATEMENT_DIGEST(@stmt);
------------------------------------------------------------------ | statement_digest(@ STMT)| ------------------------------------------------------------------ | 3bb95eeade896657c4526e74ff2a2862039d0a0fe8a9e7155b5fe492cbd78387 | ------------------------------------------------------------------ MySQL > SELECT STATEMENT_DIGEST_TEXT(@stmt);
+----------------------------------------------------------+| STATEMENT_DIGEST_TEXT(@stmt) |+----------------------------------------------------------+| SELECT * FROM `mytable` WHERE `cola` = ? AND `colb` = ? |+----------------------------------------------------------+
STATEMENT_DIGEST_TEXT(
statement
)
NULL
STATEMENT_DIGEST()
UNCOMPRESS(
string_to_uncompress
)
COMPRESS()
zlib
mysql>SELECT UNCOMPRESS(COMPRESS('any string'));
-> 'any string' mysql>SELECT UNCOMPRESS('any string');
-> NULL
UNCOMPRESSED_LENGTH(
compressed_string
)
mysql> SELECT UNCOMPRESSED_LENGTH(COMPRESS(REPEAT('a',30)));
-> 30
VALIDATE_PASSWORD_STRENGTH(
str
)
VALIDATE_PASSWORD_STRENGTH()
validate_password
validate_password
validate_password.check_user_name
VALIDATE_PASSWORD_STRENGTH()
Length < 4 | |
Length ≥ 4 and <validate_password.length | |
LOW | |
MEDIUM | |
STRONG |
BENCHMARK() | |
CHARSET() | |
COERCIBILITY() | |
COLLATION() | |
CONNECTION_ID() | |
CURRENT_ROLE() | |
CURRENT_USER()
| |
DATABASE() | |
FOUND_ROWS() | |
ICU_VERSION() | |
LAST_INSERT_ID() | |
ROLES_GRAPHML() | |
ROW_COUNT() | |
SCHEMA() | |
SESSION_USER() | |
SYSTEM_USER() | |
USER() | |
VERSION() |
BENCHMARK()
expr
count
mysql> SELECT BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye'));
+---------------------------------------------------+
| BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye')) |
+---------------------------------------------------+
| 0 |
+---------------------------------------------------+
1 row in set (4.74 sec)
BENCHMARK()
BENCHMARK()
BENCHMARK(10, (SELECT * FROM
t))
SELECT
expr
N
N
expr
N
N
BENCHMARK()
mysql>SELECT CHARSET('abc');
-> 'utf8' mysql>SELECT CHARSET(CONVERT('abc' USING latin1));
-> 'latin1' mysql>SELECT CHARSET(USER());
-> 'utf8'
mysql>SELECT COERCIBILITY('abc' COLLATE utf8_swedish_ci);
-> 0 mysql>SELECT COERCIBILITY(USER());
-> 3 mysql>SELECT COERCIBILITY('abc');
-> 4 mysql>SELECT COERCIBILITY(1000);
-> 5
0 | COLLATE | |
1 | ||
2 | ||
3 | USER() | |
4 | ||
5 | ||
5 | NULL
|
mysql>SELECT COLLATION('abc');
-> 'utf8_general_ci' mysql>SELECT COLLATION(_utf8mb4'abc');
-> 'utf8mb4_0900_ai_ci' mysql>SELECT COLLATION(_latin1'abc');
-> 'latin1_swedish_ci'
CONNECTION_ID()
INFORMATION_SCHEMA.PROCESSLIST
SHOW PROCESSLIST
threads
MySQL的> SELECT CONNECTION_ID();
> 23786
utf8
sql_quote_show_create
GRANT 'r1', 'r2' TO 'u1'@'localhost'; SET DEFAULT ROLE ALL TO 'u1'@'localhost';
u1
CURRENT_ROLE()
SET
ROLE
MySQL的> SELECT CURRENT_ROLE();
------------------- | current_role() | ------------------- | ` R1 ` @ ` % `,` R2 ` @ ` % ` | ------------------- MySQL > SET ROLE 'r1'; SELECT CURRENT_ROLE();
---------------- | current_role() | ---------------- | ` R1 ` @ ` % ` | ----------------
utf8
CURRENT_USER()
USER()
MySQL的> SELECT USER();
-> 'davida@localhost'mysql>SELECT * FROM mysql.user;
错误1044:拒绝访问用户“'@'本地主机'数据库' mysql'mysql > SELECT CURRENT_USER();
→“localhost是
davida
USER()
CURRENT_USER()
CURRENT_USER()
SQL SECURITY INVOKER
CURRENT_USER()
SQL
SECURITY
CURRENT_USER()
USER()
SESSION_USER()
CURRENT_USER()
CURRENT_USER()
CURRENT_USER()
utf8
DATABASE()
mysql> SELECT DATABASE();
-> 'test'
DATABASE()
SELECT
LIMIT
SELECT
FOUND_ROWS()
MySQL的> SELECT SQL_CALC_FOUND_ROWS * FROM
tbl_name
-> WHERE id > 100 LIMIT 10;
MySQL的> SELECT FOUND_ROWS();
SELECT
SELECT
SQL_CALC_FOUND_ROWS
SELECT
FOUND_ROWS()
FOUND_ROWS()
FOUND_ROWS()
LIMIT 50, 10
FOUND_ROWS()
mysql>SELECT SQL_CALC_FOUND_ROWS * FROM ... ;
mysql>SET @rows = FOUND_ROWS();
SELECT
SQL_CALC_FOUND_ROWS
SQL_CALC_FOUND_ROWS
FOUND_ROWS()
FOUND_ROWS()
SQL_CALC_FOUND_ROWS
FOUND_ROWS()
UNION
SELECT
UNION
SELECT
UNION
UNION
SQL_CALC_FOUND_ROWS
UNION
SQL_CALC_FOUND_ROWS
UNION
FOUND_ROWS()
UNION ALL
UNION
FOUND_ROWS()
LIMIT
UNION
UNION
FOUND_ROWS()
SELECT
FOUND_ROWS()
LAST_INSERT_ID()
LAST_INSERT_ID(
expr
)
LAST_INSERT_ID()
AUTO_INCREMENT
INSERT
LAST_INSERT_ID()
LAST_INSERT_ID()
AUTO_INCREMENT
MySQL的> SELECT LAST_INSERT_ID();
> 195
LAST_INSERT_ID()
LAST_INSERT_ID()
INSERT
LAST_INSERT_ID()
LAST_INSERT_ID()
LAST_INSERT_ID(
expr
)
LAST_INSERT_ID()
LAST_INSERT_ID()
ROLLBACK
LAST_INSERT_ID()
ROLLBACK
LAST_INSERT_ID()
LAST_INSERT_ID()
LAST_INSERT_ID()
AUTO_INCREMENT
AUTO_INCREMENT
LAST_INSERT_ID()
NULL
INSERT
LAST_INSERT_ID()
INSERT
mysql>USE test;
mysql>CREATE TABLE t (
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(10) NOT NULL
);
mysql>INSERT INTO t VALUES (NULL, 'Bob');
mysql>SELECT * FROM t;
+----+------+ | id | name | +----+------+ | 1 | Bob | +----+------+ mysql>SELECT LAST_INSERT_ID();
+------------------+ | LAST_INSERT_ID() | +------------------+ | 1 | +------------------+ mysql>INSERT INTO t VALUES
(NULL, 'Mary'), (NULL, 'Jane'), (NULL, 'Lisa');
mysql>SELECT * FROM t;
+----+------+ | id | name | +----+------+ | 1 | Bob | | 2 | Mary | | 3 | Jane | | 4 | Lisa | +----+------+ mysql>SELECT LAST_INSERT_ID();
+------------------+ | LAST_INSERT_ID() | +------------------+ | 2 | +------------------+
INSERT
2
LAST_INSERT_ID()
SELECT
INSERT
IGNORE
LAST_INSERT_ID()
AUTO_INCREMENT
AUTO_INCREMENT
innodb_autoinc_lock_mode
2
MySQL的> USE test;
MySQL的> SELECT @@innodb_autoinc_lock_mode;
* * E / CN.4 / Sub.2 / AC.5 / 2001 / 1 . CREATE TABLE `t` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`val` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `i1` (`val`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#插入两rowsmysql > INSERT INTO t (val) VALUES (1),(2);
# With auto_increment_offset=1, the inserted rows# result in an AUTO_INCREMENT value of 3mysql>SHOW CREATE TABLE t\G
*************************** 1. row *************************** Table: tCreate Table: CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `val` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `i1` (`val`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1# LAST_INSERT_ID() returns the first automatically generated# value that is successfully inserted for the AUTO_INCREMENT columnmysql>SELECT LAST_INSERT_ID();
------------------ | last_insert_id() | ------------------ | 1 | ------------------ #尝试插入重复的行失败,但错误是忽视MySQL > INSERT IGNORE INTO t (val) VALUES (1),(2);
Query OK, 0 rows affected (0.00 sec)Records: 2 Duplicates: 2 Warnings: 0# With innodb_autoinc_lock_mode=1, the AUTO_INCREMENT counter# is incremented for the ignored rowsmysql>SHOW CREATE TABLE t\G
*************************** 1. row *************************** Table: tCreate Table: CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `val` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `i1` (`val`)) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1# The LAST_INSERT_ID is unchanged because the previous insert was unsuccessfulmysql>SELECT LAST_INSERT_ID();
_ ------------------ |负荷_ ID插入(1)| | | ----------------- -----------------
expr
LAST_INSERT_ID()
LAST_INSERT_ID()
mysql>CREATE TABLE sequence (id INT NOT NULL);
mysql>INSERT INTO sequence VALUES (0);
mysql>UPDATE sequence SET id=LAST_INSERT_ID(id+1);
mysql>SELECT LAST_INSERT_ID();
UPDATE
LAST_INSERT_ID()
SELECT
mysql_insert_id()
LAST_INSERT_ID()
UPDATE
SELECT
mysql_insert_id()
mysql_insert_id()
INSERT
UPDATE
LAST_INSERT_ID(
expr
)SELECT
SET
utf8
ROLE_ADMIN
SUPER
<graphml>
mysql> SELECT ROLES_GRAPHML();
+---------------------------------------------------+
| ROLES_GRAPHML() |
+---------------------------------------------------+
| <?xml version="1.0" encoding="gb3212"?><graphml /> |
+---------------------------------------------------+
ROW_COUNT()
CREATE TABLE
DROP TABLE
SELECT
UPDATE
INSERT
DELETE
ALTER
TABLE
LOAD DATA
INFILE
SELECT
SELECT * FROM t1
ROW_COUNT()
file_name
ROW_COUNT()
SIGNAL
UPDATE
mysql_real_connect()
WHERE
REPLACE
INSERT
... ON DUPLICATE KEY UPDATE
ROW_COUNT()
mysql_affected_rows()
mysql>INSERT INTO t VALUES(1),(2),(3);
Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql>SELECT ROW_COUNT();
+-------------+ | ROW_COUNT() | +-------------+ | 3 | +-------------+ 1 row in set (0.00 sec) mysql>DELETE FROM t WHERE i IN(1,2);
Query OK, 2 rows affected (0.00 sec) mysql>SELECT ROW_COUNT();
+-------------+ | ROW_COUNT() | +-------------+ | 2 | +-------------+ 1 row in set (0.00 sec)
ROW_COUNT()
DATABASE()
utf8
MySQL的> SELECT USER();
> @本地主机是-戴维达
CURRENT_USER()
utf8
version
binlog_format
mysql> SELECT VERSION();
-> '8.0.14-standard'
ER_GIS_DIFFERENT_SRIDS
'GEOMETRYCOLLECTION()'
ST_GeomFromText()
ST_MPointFromText()
ST_GeomFromText()
ST_MPointFromText('MULTIPOINT (1 1, 2 2, 3 3)') ST_MPointFromText('MULTIPOINT ((1 1), (2 2), (3 3))')
ST_GeomFromText()
'GEOMETRYCOLLECTION()'
ST_AsWKT()
mysql>SET @s1 = ST_GeomFromText('GEOMETRYCOLLECTION()');
mysql>SET @s2 = ST_GeomFromText('GEOMETRYCOLLECTION EMPTY');
mysql>SELECT ST_AsWKT(@s1), ST_AsWKT(@s2);
+--------------------------+--------------------------+ | ST_AsWKT(@s1) | ST_AsWKT(@s2) | +--------------------------+--------------------------+ | GEOMETRYCOLLECTION EMPTY | GEOMETRYCOLLECTION EMPTY | +--------------------------+--------------------------+
NULL
NULL
options
key
=value
key
lat-long
srid-defined
options
NULL
options
ER_SRS_NOT_FOUND
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
ST_GeomCollFromText(
wkt
[,
srid
[,
options
]])ST_GeometryCollectionFromText(
wkt
[,
srid
[,
options
]])ST_GeomCollFromTxt(
wkt
[,
srid
[,
options
]])
GeometryCollection
mysql>SET @g = "MULTILINESTRING((10 10, 11 11), (9 9, 10 10))";
mysql>SELECT ST_AsText(ST_GeomCollFromText(@g));
+--------------------------------------------+ | ST_AsText(ST_GeomCollFromText(@g)) | +--------------------------------------------+ | MULTILINESTRING((10 10,11 11),(9 9,10 10)) | +--------------------------------------------+
ST_GeomFromText(
wkt
[,
srid
[,
options
]])ST_GeometryFromText(
wkt
[,
srid
[,
options
]])
ST_LineFromText(
wkt
[,
srid
[,
options
]])ST_LineStringFromText(
wkt
[,
srid
[,
options
]])
LineString
ST_MLineFromText(
wkt
[,
srid
[,
options
]])ST_MultiLineStringFromText(
wkt
[,
srid
[,
options
]])
MultiLineString
ST_MPointFromText(
wkt
[,
srid
[,
options
]])ST_MultiPointFromText(
wkt
[,
srid
[,
options
]])
MultiPoint
ST_MPolyFromText(
wkt
[,
srid
[,
options
]])ST_MultiPolygonFromText(
wkt
[,
srid
[,
options
]])
MultiPolygon
ST_PointFromText(
wkt
[,
srid
[,
options
]])
Point
ST_PointFromText()
ST_PolyFromText(
wkt
[,
srid
[,
options
]])ST_PolygonFromText(
wkt
[,
srid
[,
options
]])
Polygon
BLOB
ST_GeomFromWKB()
ST_GeomFromWKB(Point(0,
0))
ST_GeomFromWKB(Point(0,
0), 4326)
ST_GeomFromWKB(ST_AsWKB(Point(0,
0)), 4326)
NULL
options
key
=value
key
lat-long
srid-defined
options
NULL
options
ER_SRS_NOT_FOUND
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
ST_GeomCollFromWKB(
wkb
[,
srid
[,
options
]])ST_GeometryCollectionFromWKB(
wkb
[,
srid
[,
options
]])
GeometryCollection
ST_GeomFromWKB(
wkb
[,
srid
[,
options
]])ST_GeometryFromWKB(
wkb
[,
srid
[,
options
]])
ST_LineFromWKB(
wkb
[,
srid
[,
options
]])ST_LineStringFromWKB(
wkb
[,
srid
[,
options
]])
LineString
ST_MLineFromWKB(
wkb
[,
srid
[,
options
]])ST_MultiLineStringFromWKB(
wkb
[,
srid
[,
options
]])
MultiLineString
ST_MPointFromWKB(
wkb
[,
srid
[,
options
]])ST_MultiPointFromWKB(
wkb
[,
srid
[,
options
]])
MultiPoint
ST_MPolyFromWKB(
wkb
[,
srid
[,
options
]])ST_MultiPolygonFromWKB(
wkb
[,
srid
[,
options
]])
MultiPolygon
ST_PointFromWKB(
wkb
[,
srid
[,
options
]])
Point
ST_PointFromWKB()
ST_PolyFromWKB(
wkb
[,
srid
[,
options
]])ST_PolygonFromWKB(
wkb
[,
srid
[,
options
]])
Polygon
NULL
Point()
INSERT INTO t1 (pt_col) VALUES(Point(1,2));
GeomCollection
GeomCollection()
GeomCollection()
ST_GeomFromText()
'GEOMETRYCOLLECTION()'
GeomCollection()
GeometryCollection()
GeomCollection()
GeometryCollection(
g
[, g
] ...)
GeomCollection
GeometryCollection()
GeometryCollection()
ST_GeomFromText()
'GEOMETRYCOLLECTION()'
GeomCollection()
GeometryCollection()
GeomCollection()
LineString
Point
MultiLineString(
ls
[, ls
] ...)
MultiLineString
LineString
MultiPoint
Point
MultiPolygon(
poly
[, poly
] ...)
MultiPolygon
Polygon
Point
Polygon
LineString
LineString
ST_GeomFromText()
'GEOMETRYCOLLECTION()'
GeometryCollection()
ST_AsWKT()
mysql>SET @s1 = ST_GeomFromText('GEOMETRYCOLLECTION()');
mysql>SET @s2 = ST_GeomFromText('GEOMETRYCOLLECTION EMPTY');
mysql>SELECT ST_AsWKT(@s1), ST_AsWKT(@s2);
+--------------------------+--------------------------+ | ST_AsWKT(@s1) | ST_AsWKT(@s2) | +--------------------------+--------------------------+ | GEOMETRYCOLLECTION EMPTY | GEOMETRYCOLLECTION EMPTY | +--------------------------+--------------------------+ mysql>SELECT ST_AsWKT(GeomCollection());
+----------------------------+ | ST_AsWKT(GeomCollection()) | +----------------------------+ | GEOMETRYCOLLECTION EMPTY | +----------------------------+
NULL
ER_GIS_INVALID_DATA
ER_WARN_SRS_NOT_FOUND_AXIS_ORDER
options
key
=value
key
lat-long
srid-defined
options
NULL
options
NULL
ST_AsBinary(
g
[, options
])ST_AsWKB(
g
[, options
])
options
ST_AsBinary()
ST_AsWKB()
MySQL的> SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)', 4326);
MySQL的> SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g)));
----------------------------------------- | _ astext圣(圣_ geomfromwkb(ST _ aswkb(@(g))(5)| ----------------------------------------- | linestring 0.10>5 10)| ----------------------------------------- MySQL SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat')));
+----------------------------------------------------------------+| ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=long-lat'))) |+----------------------------------------------------------------+| LINESTRING(0 5,5 10,10 15) |+----------------------------------------------------------------+mysql>SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long')));
+----------------------------------------------------------------+| ST_AsText(ST_GeomFromWKB(ST_AsWKB(@g, 'axis-order=lat-long'))) |+----------------------------------------------------------------+| LINESTRING(5 0,10 5,15 10) |+----------------------------------------------------------------+
ST_AsText(
g
[,
options
])ST_AsWKT(
g
[, options
])
options
ST_AsText()
ST_AsWKT()
MySQL的> SET @g = 'LineString(1 1,2 2,3 3)';
MySQL的> SELECT ST_AsText(ST_GeomFromText(@g));
| --------------------------------(ST ST _ astext _ geomfromtext(@ g)(1)| -------------------------------- | linestring 1.2 2 3)| ------------------------------
MultiPoint
MySQL的> SELECT ST_AsText(ST_GeomFromText(@mp));
--------------------------------- | _ astext圣(圣_ geomfromtext(@ MP))| --------------------------------- |多点(1,1)、(2)、(3)| ---------------------------------)
ST_SwapXY()
MySQL的> SET @g = ST_LineFromText('LINESTRING(0 5,5 10,10 15)');
MySQL的> SELECT ST_AsText(@g);
| ----------------------------(G ST _ astext @ | | linestring ----------------------------(0)10 15 | ---------------------------- MySQL 5.5)> SELECT ST_AsText(ST_SwapXY(@g));
它|圣(圣_ astext _ swapxy(@(G)的)| ----------------------------(5 0、10 | linestring)| ----------------------------
NULL
ST_Area()
Polygon
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_DATA_OUT_OF_RANGE
ER_SRS_NOT_FOUND
NULL
g
ST_Dimension()
MySQL的> SELECT ST_Dimension(ST_GeomFromText('LineString(1 1,2 2)'));
三维| ------------------------------------------------------(ST ST _ _ geomfromtext(linestring(1 1 2)1)| ------------------------------------------------------ | | ------------------------------------------------------
g
POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
MySQL的> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,2 2)')));
---------------------------------------------------------------- | st_astext(st_envelope(st_geomfromtext('linestring(1、2)')))| ---------------------------------------------------------------- |多边形((1 1,2 1 2 2,1))| ----------------------------------------------------------------
ST_Envelope()
MySQL的> SELECT ST_AsText(ST_Envelope(ST_GeomFromText('LineString(1 1,1 2)')));
---------------------------------------------------------------- | st_astext(st_envelope(st_geomfromtext('linestring(1 1,1 2)')))| ---------------------------------------------------------------- |线(1 1,1 2)| ----------------------------------------------------------------
ST_Envelope()
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
g
ST_GeometryType()
MySQL的> SELECT ST_GeometryType(ST_GeomFromText('POINT(1 1)'));
------------------------------------------------ | st_geometrytype(st_geomfromtext('point(1 1)'))| ------------------------------------------------ |点| ------------------------------------------------
EMPTY
ST_IsEmpty()
g
ST_IsSimple()
ST_IsSimple()
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
g
ST_SRID()
g
ST_SRID()
ST_SRID()
ST_SRID()
ER_SRS_NOT_FOUND
ST_SRID(
g
,
target_srid
)ST_Transform(
g
,
target_srid
)
ST_SRID()
ST_Transform()
MySQL的> SET @g = ST_GeomFromText('LineString(1 1,2 2)', 0);
MySQL的> SELECT ST_SRID(@g);
对|圣_法(“G)| ------------------ | 0 |对MySQL的> SET @g = ST_SRID(@g, 4326);
MySQL的> SELECT ST_SRID(@g);
一个多月以前评论
ST_SRID()
SET @g1 = ST_SRID(Point(1, 1), 4326);
SET @g1 = ST_PointFromText('POINT(1 1)', 4326); SET @g1 = ST_GeomFromText('POINT(1 1)', 4326);
ST_SRID()
Point
ST_X()
ST_Y()
Point
ST_Longitude()
ST_Latitude()
NULL
Point
ER_UNEXPECTED_GEOMETRY_TYPE
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
-inf
NaN
ER_DATA_OUT_OF_RANGE
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
NULL
ST_Latitude(
p
[, new_latitude_val
])
Point
p
ST_Latitude()
p
ST_Latitude()
ST_Latitude()
ER_SRS_NOT_GEOGRAPHIC
MySQL的> SET @pt = ST_GeomFromText('POINT(45 90)', 4326);
MySQL的> SELECT ST_Latitude(@pt);
------------------ | st_latitude(铂)| ------------------ | 45 | ------------------ MySQL > SELECT ST_AsText(ST_Latitude(@pt, 10));
--------------------------------- |圣(圣_ astext _纬度(@),10)(10)| --------------------------------- |点| --------------------------------- 90)
ST_Longitude(
p
[, new_longitude_val
])
Point
p
ST_Longitude()
p
ST_Longitude()
ST_Longitude()
ER_SRS_NOT_GEOGRAPHIC
MySQL的> SET @pt = ST_GeomFromText('POINT(45 90)', 4326);
MySQL的> SELECT ST_Longitude(@pt);
向|圣_ longitude(@ PT)|向| 90 |向MySQL > SELECT ST_AsText(ST_Longitude(@pt, 10));
---------------------------------- |圣_ astext(ST _ longitude(@ PT,10))| ---------------------------------- |(10点45 | ----------------------------------)
Point
p
ST_X()
p
ST_X()
Point
ST_X()
MySQL的> SELECT ST_X(Point(56.7, 53.34));
| -----------------------------(ST _ X点(56.7,| 53.34%)----------------------------- | 56.7 | ----------------------------- MySQL > SELECT ST_AsText(ST_X(Point(56.7, 53.34), 10.5));
------------------------------------------- | _ astext圣(圣_ x(点(56.7 53.34%,10.5,)))| ------------------------------------------- |点(10.5 | ------------------------------------------- 53.34%)
Point
p
ST_Y()
p
ST_Y()
Point
ST_Y()
MySQL的> SELECT ST_Y(Point(56.7, 53.34));
_ ----------------------------- | ST Y(点(56.7,| 53.34%)----------------------------- | 53.34% MySQL > | ----------------------------- SELECT ST_AsText(ST_Y(Point(56.7, 53.34), 10.5));
------------------------------------------- | _ astext圣(圣_ Y(点(56.7 53.34%,10.5,)))| ------------------------------------------- |点(56.7 | ------------------------------------------- 10.5)
LineString
LineString
MultiLineString
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
NULL
Point
ls
ST_EndPoint()
MySQL的> SET @ls = 'LineString(1 1,2 2,3 3)';
MySQL的> SELECT ST_AsText(ST_EndPoint(ST_GeomFromText(@ls)));
---------------------------------------------- | _ astext圣(圣_端点(ST _ geomfromtext(@ LS)))| ---------------------------------------------- |点(3)| ----------------------------------------------
LineString
ls
ST_IsClosed()
ls
ST_StartPoint()
ST_EndPoint()
MultiLineString
ls
ST_IsClosed()
ls
ST_StartPoint()
ST_EndPoint()
ls
ST_IsClosed()
ls
ls
ST_IsClosed()
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
MySQL的> SET @ls1 = 'LineString(1 1,2 2,3 3,2 2)';
MySQL的> SET @ls2 = 'LineString(1 1,2 2,3 3,1 1)';
MySQL的> SELECT ST_IsClosed(ST_GeomFromText(@ls1));
------------------------------------ | st_isclosed(st_geomfromtext(@ LS1))| ------------------------------------ | 0 | ------------------------------------ MySQL > SELECT ST_IsClosed(ST_GeomFromText(@ls2));
------------------------------------ | st_isclosed(st_geomfromtext(@ LS2))| ------------------------------------ | 1 | ------------------------------------ MySQL > SET @ls3 = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
MySQL的> SELECT ST_IsClosed(ST_GeomFromText(@ls3));
------------------------------------ | st_isclosed(st_geomfromtext(@ LS3))| ------------------------------------ | 0 | ------------------------------------
LineString
ls
ST_Length()
LineString
MultiLineString
LineString
MultiLineString
ST_Length()
LineString
NULL
+inf
ER_DATA_OUT_OF_RANGE
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
mysql>SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT ST_Length(ST_GeomFromText(@ls));
+---------------------------------+ | ST_Length(ST_GeomFromText(@ls)) | +---------------------------------+ | 2.8284271247461903 | +---------------------------------+ mysql>SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
mysql>SELECT ST_Length(ST_GeomFromText(@mls));
+----------------------------------+ | ST_Length(ST_GeomFromText(@mls)) | +----------------------------------+ | 4.242640687119286 | +----------------------------------+
Point
ls
ST_NumPoints()
MySQL的> SET @ls = 'LineString(1 1,2 2,3 3)';
MySQL的> SELECT ST_NumPoints(ST_GeomFromText(@ls));
| _ numpoints ------------------------------------圣(圣_ geomfromtext(@ LS)3)| ------------------------------------ | | ------------------------------------
N
Linestring
ls
ST_PointN()
MySQL的> SET @ls = 'LineString(1 1,2 2,3 3)';
MySQL的> SELECT ST_AsText(ST_PointN(ST_GeomFromText(@ls),2));
---------------------------------------------- | _ astext圣(圣_ pointn(ST _ geomfromtext(@ LS),2))| ---------------------------------------------- |点(2)| ----------------------------------------------
Point
ls
ST_StartPoint()
MySQL的> SET @ls = 'LineString(1 1,2 2,3 3)';
MySQL的> SELECT ST_AsText(ST_StartPoint(ST_GeomFromText(@ls)));
_ astext ------------------------------------------------ |圣(圣_ startpoint(ST _ geomfromtext(@ LS)))| ------------------------------------------------ |点(1,1)| ------------------------------------------------
Polygon
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_GIS_DIFFERENT_SRIDS
NULL
Polygon
ST_Area()
Polygon
ER_UNEXPECTED_GEOMETRY_TYPE
Polygon
MultiPolygon
Polygon
MultiPolygon
+inf
ER_DATA_OUT_OF_RANGE
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
ST_Area()
NULL
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
MySQL的> SET @poly =
'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';
MySQL的> SELECT ST_Area(ST_GeomFromText(@poly));
--------------------------------- | st_area(st_geomfromtext(@聚))| --------------------------------- | 4 | --------------------------------- MySQL > SET @mpoly =
-> 'MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))';
MySQL的> SELECT ST_Area(ST_GeomFromText(@mpoly));
---------------------------------- | st_area(st_geomfromtext(@ mpoly))| ---------------------------------- | 8 | ----------------------------------
Polygon
Point
MultiPolygon
MultiPoint
ST_Centroid()
NULL
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
MySQL的> SET @poly =
-> ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');
MySQL的> SELECT ST_GeometryType(@poly),ST_AsText(ST_Centroid(@poly));
------------------------ -------------------------------------------- | st_geometrytype(@聚)| st_astext(st_centroid(@聚))| ------------------------ -------------------------------------------- |多边形|点(4.958333333333333 4.958333333333333)| ------------------------ --------------------------------------------
Polygon
poly
ST_ExteriorRing()
MySQL的> SET @poly =
-> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
MySQL的> SELECT ST_AsText(ST_ExteriorRing(ST_GeomFromText(@poly)));
---------------------------------------------------- | st_astext(st_exteriorring(st_geomfromtext(@聚)))| ---------------------------------------------------- |线(0、0、0 0)| ----------------------------------------------------
N
poly
ST_InteriorRingN()
MySQL的> SET @poly =
-> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
MySQL的> SELECT ST_AsText(ST_InteriorRingN(ST_GeomFromText(@poly),1));
------------------------------------------------------- | st_astext(st_interiorringn(st_geomfromtext(@聚),1))| ------------------------------------------------------- |线(1 1 2 2 1,1)| -------------------------------------------------------
ST_NumInteriorRing(
poly
)ST_NumInteriorRings(
poly
)
Polygon
poly
ST_NumInteriorRing()
ST_NuminteriorRings()
MySQL的> SET @poly =
-> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
MySQL的> SELECT ST_NumInteriorRings(ST_GeomFromText(@poly));
--------------------------------------------- | st_numinteriorrings(st_geomfromtext(@聚))| --------------------------------------------- | 1 | ---------------------------------------------
GeometryCollection
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
NULL
N
gc
ST_GeometryN()
MySQL的> SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
MySQL的> SELECT ST_AsText(ST_GeometryN(ST_GeomFromText(@gc),1));
------------------------------------------------- | st_astext(st_geometryn(st_geomfromtext(@ GC),1))| ------------------------------------------------- |点(1 1)| -------------------------------------------------
GeometryCollection
gc
ST_NumGeometries()
MySQL的> SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
MySQL的> SELECT ST_NumGeometries(ST_GeomFromText(@gc));
---------------------------------------- | _ numgeometries圣(圣_ geomfromtext(@ GC)2)| ---------------------------------------- | | ----------------------------------------
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_GIS_DIFFERENT_SRIDS
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
NULL
ST_Buffer(
g
,
d
[,
strategy1
[,
strategy2
[,
strategy3
]]])
g
d
ST_Buffer()
ST_Buffer()
MySQL的> SET @pt = ST_GeomFromText('POINT(0 0)');
MySQL的> SELECT ST_AsText(ST_Buffer(@pt, 0));
------------------------------ | st_astext(st_buffer(铂,0))| ------------------------------ |点(0 0)| ------------------------------
ST_Buffer()
MultiPolygon
MultiPolygon
ST_Buffer()
ST_Buffer_Strategy()
Point
ST_Buffer_Strategy('point_circle',
32)
LineString
Polygon
ST_Buffer_Strategy('join_round',
32)
LineString
ST_Buffer_Strategy('end_round',
32)
ST_Buffer()
Point
LineString
Polygon
ER_WRONG_ARGUMENTS
ER_WRONG_ARGUMENTS
MySQL的> SET @pt = ST_GeomFromText('POINT(0 0)');
MySQL的> SET @pt_strategy = ST_Buffer_Strategy('point_square');
MySQL的> SELECT ST_AsText(ST_Buffer(@pt, 2, @pt_strategy));
-------------------------------------------- | st_astext(st_buffer(铂、2、@ pt_strategy))| -------------------------------------------- |多边形((- 2 - 2 - 2,2,2 2,2 2))| --------------------------------------------
MySQL的> SET @ls = ST_GeomFromText('LINESTRING(0 0,0 5,5 5)');
MySQL的> SET @end_strategy = ST_Buffer_Strategy('end_flat');
MySQL的> SET @join_strategy = ST_Buffer_Strategy('join_round', 10);
MySQL的> SELECT ST_AsText(ST_Buffer(@ls, 5, @end_strategy, @join_strategy))
--------------------------------------------------------------- | st_astext(st_buffer(@ LS,五,@ end_strategy,@ join_strategy))| --------------------------------------------------------------- |多边形((5 5 0 10,-3.5355339059327373 8.535533905932738,| | - 5 5,5 0 0.5 0.5五))| ---------------------------------------------------------------
ST_Buffer_Strategy(
strategy
[,
points_per_circle
])
ST_Buffer()
'point_circle'
'join_round'
'end_round'
'point_circle'
'join_miter'
points_per_circle
points_per_circle
max_points_in_geometry
ST_Buffer()
ST_Buffer_Strategy()
ER_WRONG_ARGUMENTS
'point_square'
points_per_circle
ER_WRONG_ARGUMENTS
g
MultiPoint
ST_ConvexHull()
NULL
MySQL的> SET @g = 'MULTIPOINT(5 0,25 0,15 10,15 25)';
MySQL的> SELECT ST_AsText(ST_ConvexHull(ST_GeomFromText(@g)));
----------------------------------------------- | st_astext(st_convexhull(st_geomfromtext(@ g)))| ----------------------------------------------- |多边形((5 0 0 0 | ----------------------------------------------- 25,5))
g1
g2
ST_Difference()
MySQL的> SET @g1 = Point(1,1), @g2 = Point(2,2);
MySQL的> SELECT ST_AsText(ST_Difference(@g1, @g2));
1 . Stón de difference(@g1,@g2)
g1
g2
ST_Intersection()
MySQL的> SET @g1 = ST_GeomFromText('LineString(1 1, 3 3)');
MySQL的> SET @g2 = ST_GeomFromText('LineString(1 3, 3 1)');
MySQL的> SELECT ST_AsText(ST_Intersection(@g1, @g2));
* * * * * * * * * * * * * * * * * * *
g1
g2
g1
symdifference g2
:= (g1
联盟 g2
差异() g1
交叉 g2
)
ST_SymDifference(g1
,g2
) = ST_Difference(ST_Union(g1
,g2
), ST_Intersection(g1
,g2
))
ST_SymDifference()
MySQL的> SET @g1 = Point(1,1), @g2 = Point(2,2);
MySQL的> SELECT ST_AsText(ST_SymDifference(@g1, @g2));
--------------------------------------- | st_astext(st_symdifference(@ @ G1、G2))| --------------------------------------- |多点((1,1),(2,2))| ---------------------------------------
target_srid
ST_Transform()
ER_SRS_NOT_FOUND
ST_Transform()
ER_TRANSFORM_SOURCE_SRS_NOT_SUPPORTED
ST_Transform()
ER_TRANSFORM_TARGET_SRS_NOT_SUPPORTED
ER_TRANSFORM_SOURCE_SRS_MISSING_TOWGS84
ER_TRANSFORM_TARGET_SRS_MISSING_TOWGS84
ST_SRID(
g
,
target_srid
)ST_Transform(
g
,
target_srid
)
ST_SRID()
ST_Transform()
MySQL的> SET @p = ST_GeomFromText('POINT(52.381389 13.064444)', 4326);
MySQL的> SELECT ST_AsText(@p);
| ----------------------------(@圣_ astext | ---------------------------- |点(P)52.381389 13.064444)| ---------------------------- MySQL > SET @p = ST_Transform(@p, 4230);
MySQL的> SELECT ST_AsText(@p);
--------------------------------------------- | ST _ astext(@ |点(P)| --------------------------------------------- 52.38208611407426 | --------------------------------------------- 13.065520672345304)
g1
g2
ST_Union()
MySQL的> SET @g1 = ST_GeomFromText('LineString(1 1, 3 3)');
MySQL的> SET @g2 = ST_GeomFromText('LineString(1 3, 3 1)');
MySQL的> SELECT ST_AsText(ST_Union(@g1, @g2));
| -------------------------------------- _ astext(ST ST _社(@ @ G1,G2的))((1 | -------------------------------------- | multilinestring 1.3(1,3)3 1)| --------------------------------------
g1
ST_Distance()
ST_Distance()
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_GIS_DIFFERENT_SRIDS
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
NULL
g1
g2
ST_Within()
ST_Contains()
g1
g1
g2
g2
g1
g1
g2
ST_Crosses()
g1
MultiPolygon
g2
MultiPoint
g1
g2
ST_Disjoint()
g1
g2
ST_Distance()
ST_Distance()
Point
MultiPoint
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
NaN
ER_GIS_INVALID_DATA
MySQL的> SET @g1 = Point(1,1);
MySQL的> SET @g2 = Point(2,2);
MySQL的> SELECT ST_Distance(@g1, @g2);
—————————————————————————— SET @g1 = ST_GeomFromText('POINT(1 1)', 4326);
MySQL的> SET @g2 = ST_GeomFromText('POINT(2 2)', 4326);
MySQL的> SELECT ST_Distance(@g1, @g2);
_ ------ | ST(@ @距离G1,G2)| ------ | 156874.3859490455 | ------
ST_Distance_Sphere()
g1
g2
ST_Equals()
mysql>SET @g1 = Point(1,1), @g2 = Point(2,2);
mysql>SELECT ST_Equals(@g1, @g1), ST_Equals(@g1, @g2);
+---------------------+---------------------+ | ST_Equals(@g1, @g1) | ST_Equals(@g1, @g2) | +---------------------+---------------------+ | 1 | 0 | +---------------------+---------------------+
g1
g2
ST_Intersects()
g1
g2
ST_Overlaps()
g1
g2
ST_Touches()
Point
g1
g2
ST_Contains()
ST_Within()
g1
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_GIS_DIFFERENT_SRIDS
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
NULL
g1
g2
MBRWithin()
MBRContains()
MySQL的> SET @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
MySQL的> SET @g2 = ST_GeomFromText('Point(1 1)');
MySQL的> SELECT MBRContains(@g1,@g2), MBRWithin(@g2,@g1);
---------------------- --------------------(@ @ | mbrcontains G1,G2的)(@ @ | mbrwithin G2,G1期)| ---------------------- ----------- | | 1 1 | ---------------------- --------------------
g1
g2
MBRCovers()
MBRCoveredBy()
MySQL的> SET @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
MySQL的> SET @g2 = ST_GeomFromText('Point(1 1)');
MySQL的> SELECT MBRCovers(@g1,@g2), MBRCoveredby(@g1,@g2);
-------------------- ----------------------- | mbrcovers(@ @ G1、G2)| mbrcoveredby(@ @ G1、G2)| -------------------- ----------------------- | 1 | 0 | -------------------- ----------------------- MySQL > SELECT MBRCovers(@g2,@g1), MBRCoveredby(@g2,@g1);
-------------------- ----------------------- | mbrcovers(@ @ G2、G1)| mbrcoveredby(@ @ G2、G1)| -------------------- ----------------------- | 0 | 1 | -------------------- -----------------------
g1
g2
MBRCoveredBy()
MBRCoveredBy()
MBRCovers()
g1
g2
MBRDisjoint()
g1
g2
MBREquals()
g1
g2
MBRIntersects()
g1
g2
MBROverlaps()
g1
g2
MBRTouches()
g1
g2
MBRContains()
MBRWithin()
MySQL的> SET @g1 = ST_GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
MySQL的> SET @g2 = ST_GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))');
MySQL的> SELECT MBRWithin(@g1,@g2), MBRWithin(@g2,@g1);
-------------------- -------------------- | mbrwithin(@ @ G1、G2)| mbrwithin(@ @ G2、G1)| -------------------- -------------------- | 1 | 0 | -------------------- --------------------
"0123456789bcdefghjkmnpqrstuvwxyz"
NULL
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
ER_SRS_NOT_FOUND
point
ER_SRS_NOT_FOUND
ER_DATA_OUT_OF_RANGE
NULL
ST_GeoHash(
longitude
,
latitude
,
max_length
)ST_GeoHash(
point
,
max_length
)
longitude
latitude
max_length
max_length
max_length
ST_GeoHash()
MySQL的> SELECT ST_GeoHash(180,0,10), ST_GeoHash(-180,-90,15);
---------------------- ------------------------- |圣_ geohash(180,0,10)|圣_ geohash(180,90,15)| ---------------------- ------------------------- | xbpbpbpbpb | 000000000000000 | ---------------------- -------------------------
ST_LatFromGeoHash(
geohash_str
)
ST_LatFromGeoHash()
geohash_str
ST_LatFromGeoHash()
MySQL的> SELECT ST_LatFromGeoHash(ST_GeoHash(45,-20,10));
------------------------------------------ |(ST ST _ latfromgeohash _ geohash(45,- 10 - 20)| ------------------------------------------ | | ------------------------------------------
ST_LongFromGeoHash(
geohash_str
)
ST_LatFromGeoHash()
geohash_str
ST_LongFromGeoHash()
ST_LongFromGeoHash()
MySQL的> SELECT ST_LongFromGeoHash(ST_GeoHash(45,-20,10));
------------------------------------------- | st_longfromgeohash(st_geohash(45,- 20,10))| ------------------------------------------- | 45 | -------------------------------------------
ST_PointFromGeoHash(
geohash_str
,
srid
)
POINT
srid
ST_LatFromGeoHash()
geohash_str
ST_PointFromGeoHash()
ST_PointFromGeoHash()
MySQL的> SET @gh = ST_GeoHash(45,-20,10);
MySQL的> SELECT ST_AsText(ST_PointFromGeoHash(@gh,0));
_ astext --------------------------------------- |圣(圣_ pointfromgeohash(@),0))| --------------------------------------- |点(45,20)| ---------------------------------------
JSON
ST_AsGeoJSON(
g
[, max_dec_digits
[,
options
]])
g
NULL
NULL
max_dec_digits
options
options | |
EPSG: | |
urn:ogc:def:crs:EPSG:: |
MySQL的> SELECT ST_AsGeoJSON(ST_GeomFromText('POINT(11.11111 12.22222)'),2);
------------------------------------------------------------- | _ asgeojson圣(圣_ geomfromtext(点(11.11111 12.22222),2)| ------------------------------------------------------------- | {“型”的“点”、“坐标”:[ 11 ],| ------------------------------------------------------------- 12.22 }
ST_GeomFromGeoJSON(
str
[, options
[,
srid
]])
str
NULL
NULL
options
options
options | |
options
srid
srid
ER_SRS_NOT_FOUND
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
crs
srid
srid
srid
crs
ER_INVALID_GEOJSON_CRS_NOT_TOP_LEVEL
type
LineString
mysql>SET @json = '{ "type": "Point", "coordinates": [102.0, 0.0]}';
mysql>SELECT ST_AsText(ST_GeomFromGeoJSON(@json));
+--------------------------------------+ | ST_AsText(ST_GeomFromGeoJSON(@json)) | +--------------------------------------+ | POINT(102 0) | +--------------------------------------+
NULL
ER_GIS_INVALID_DATA
ER_SRS_NOT_FOUND
ER_GIS_DIFFERENT_SRIDS
NULL
ST_Distance_Sphere(
g1
,
g2
[,
radius
])
Point
ST_Distance()
radius
Point
Point
ST_Distance_Sphere()
Point
Point
Point
ER_NOT_IMPLEMENTED_FOR_CARTESIAN_SRS
MultiPoint
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
ER_NOT_IMPLEMENTED_FOR_PROJECTED_SRS
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
radius
ER_NONPOSITIVE_RADIUS
ER_STD_OVERFLOW_ERROR
MySQL的> SET @pt1 = ST_GeomFromText('POINT(0 0)');
MySQL的> SET @pt2 = ST_GeomFromText('POINT(180 0)');
MySQL的> SELECT ST_Distance_Sphere(@pt1, @pt2);
-------------------------------- | st_distance_sphere(@ @ PT1,PT2)| -------------------------------- | 20015042.813723423 | --------------------------------
ST_IsValid()
POINT EMPTY
ST_IsValid()
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
mysql>SET @ls1 = ST_GeomFromText('LINESTRING(0 0,-0.00 0,0.0 0)');
mysql>SET @ls2 = ST_GeomFromText('LINESTRING(0 0, 1 1)');
mysql>SELECT ST_IsValid(@ls1);
+------------------+ | ST_IsValid(@ls1) | +------------------+ | 0 | +------------------+ mysql>SELECT ST_IsValid(@ls2);
+------------------+ | ST_IsValid(@ls2) | +------------------+ | 1 | +------------------+
Point
Polygon
pt1
pt2
ST_MakeEnvelope()
pt1
pt2
pt1
(
pt1
,
pt2
)pt1
pt2
pt1
pt2
ST_MakeEnvelope()
Point
ER_WRONG_ARGUMENTS
ER_GIS_INVALID_DATA
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
MySQL的> SET @pt1 = ST_GeomFromText('POINT(0 0)');
MySQL的> SET @pt2 = ST_GeomFromText('POINT(1 1)');
MySQL的> SELECT ST_AsText(ST_MakeEnvelope(@pt1, @pt2));
---------------------------------------- | st_astext(st_makeenvelope(@ @ PT1,PT2))| ---------------------------------------- |多边形((0 0,1 0,1 0 1,0 0))| ----------------------------------------
max_distance
ST_IsValid()
ST_Simplify()
max_distance
ER_WRONG_ARGUMENTS
MySQL的> SET @g = ST_GeomFromText('LINESTRING(0 0,0 1,1 1,1 2,2 2,2 3,3 3)');
MySQL的> SELECT ST_AsText(ST_Simplify(@g, 0.5));
--------------------------------- | st_astext(st_simplify(@ G,0.5))| --------------------------------- |线(0 1 2 3,3,0)| --------------------------------- MySQL > SELECT ST_AsText(ST_Simplify(@g, 1.0));
--------------------------------- | st_astext(st_simplify(@ G,1.0))| --------------------------------- |线(0 0 3)| ---------------------------------
POLYGON((0 0, 0 0, 0 0, 0 0, 0
0))
ST_Validate()
NULL
ST_Validate()
Polygon
ST_Validate()
ST_Validate()
ER_LONGITUDE_OUT_OF_RANGE
ER_LATITUDE_OUT_OF_RANGE
ST_Validate()
NULL
ER_GIS_INVALID_DATA
ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
MySQL的> SET @ls1 = ST_GeomFromText('LINESTRING(0 0)');
MySQL的> SET @ls2 = ST_GeomFromText('LINESTRING(0 0, 1 1)');
MySQL的> SELECT ST_AsText(ST_Validate(@ls1));
_ astext ------------------------------ |圣(圣_ validate(@ LS1)| ------------------------------ |零| ------------------------------ MySQL > SELECT ST_AsText(ST_Validate(@ls2));
------------------------------ | st_astext(st_validate(@ LS2))| ------------------------------ |线(0Ω1)| ------------------------------
JSON
json_doc
val
JSON_ARRAY() | |
JSON_ARRAY_APPEND() | |
JSON_ARRAY_INSERT() | |
-> | |
JSON_CONTAINS() | |
JSON_CONTAINS_PATH() | |
JSON_DEPTH() | |
JSON_EXTRACT() | |
->> | |
JSON_INSERT() | |
JSON_KEYS() | |
JSON_LENGTH() | |
JSON_MERGE() | |
JSON_MERGE_PATCH() | |
JSON_MERGE_PRESERVE() | |
JSON_OBJECT() | |
JSON_PRETTY() | |
JSON_QUOTE() | |
JSON_REMOVE() | |
JSON_REPLACE() | |
JSON_SEARCH() | |
JSON_SET() | |
JSON_STORAGE_FREE() | |
JSON_STORAGE_SIZE() | |
JSON_TABLE() | |
JSON_TYPE() | |
JSON_UNQUOTE() | |
JSON_VALID() |
JSON_ARRAYAGG()
JSON_OBJECTAGG()
JSON_PRETTY()
JSON_STORAGE_SIZE()
JSON_STORAGE_FREE()
mysql> SELECT JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME());
+---------------------------------------------+
| JSON_ARRAY(1, "abc", NULL, TRUE, CURTIME()) |
+---------------------------------------------+
| [1, "abc", null, true, "11:30:24.000000"] |
+---------------------------------------------+
JSON_OBJECT([
key
,
val
[,
key
,
val
] ...])
NULL
MySQL的> SELECT JSON_OBJECT('id', 87, 'name', 'carrot');
_ -----------------------------------------(| JSON对象id,name是87,是胡萝卜,是| -----------------------------------------):87 | {“ID”,“name”,“胡萝卜”| ----------------------------------------- }
utf8mb4
NULL
mysql>SELECT JSON_QUOTE('null'), JSON_QUOTE('"null"');
+--------------------+----------------------+ | JSON_QUOTE('null') | JSON_QUOTE('"null"') | +--------------------+----------------------+ | "null" | "\"null\"" | +--------------------+----------------------+ mysql>SELECT JSON_QUOTE('[1, 2, 3]');
+-------------------------+ | JSON_QUOTE('[1, 2, 3]') | +-------------------------+ | "[1, 2, 3]" | +-------------------------+
JSON
CAST(
value
AS
JSON)
JSON_ARRAYAGG()
JSON_OBJECTAGG()
JSON_CONTAINS(
target
,
candidate
[,
path
])
candidate
target
path
NULL
target
candidate
path
**
JSON_CONTAINS_PATH()
JSON_TYPE()
DECIMAL
mysql>SET @j = '{"a": 1, "b": 2, "c": {"d": 4}}';
mysql>SET @j2 = '1';
mysql>SELECT JSON_CONTAINS(@j, @j2, '$.a');
+-------------------------------+ | JSON_CONTAINS(@j, @j2, '$.a') | +-------------------------------+ | 1 | +-------------------------------+ mysql>SELECT JSON_CONTAINS(@j, @j2, '$.b');
+-------------------------------+ | JSON_CONTAINS(@j, @j2, '$.b') | +-------------------------------+ | 0 | +-------------------------------+ mysql>SET @j2 = '{"d": 4}';
mysql>SELECT JSON_CONTAINS(@j, @j2, '$.a');
+-------------------------------+ | JSON_CONTAINS(@j, @j2, '$.a') | +-------------------------------+ | 0 | +-------------------------------+ mysql>SELECT JSON_CONTAINS(@j, @j2, '$.c');
+-------------------------------+ | JSON_CONTAINS(@j, @j2, '$.c') | +-------------------------------+ | 1 | +-------------------------------+
JSON_CONTAINS_PATH(
json_doc
,
one_or_all
,
path
[,
path
] ...)
NULL
json_doc
path
one_or_all
'all'
JSON_CONTAINS()
one_or_all
'one'
'all'
MySQL的> SET @j = '{"a": 1, "b": 2, "c": {"d": 4}}';
MySQL的> SELECT JSON_CONTAINS_PATH(@j, 'one', '$.a', '$.e');
--------------------------------------------- | JSON _ contains _路径(一,J @,和美元,和美元)| --------------------------------------------- | --------------------------------------------- MySQL |>1 SELECT JSON_CONTAINS_PATH(@j, 'all', '$.a', '$.e');
--------------------------------------------- | json_contains_path(@ J,'所有','一','美元。美元。E)| --------------------------------------------- | 0 | --------------------------------------------- MySQL > SELECT JSON_CONTAINS_PATH(@j, 'one', '$.c.d');
---------------------------------------- | json_contains_path(@ J,'一','美元。C.”)| ---------------------------------------- | 1 | ---------------------------------------- MySQL > SELECT JSON_CONTAINS_PATH(@j, 'one', '$.a.d');
---------------------------------------- | JSON _ contains _路径(一,J”,.a.d美元)| ---------------------------------------- | | ---------------------------------------- 0
JSON_EXTRACT(
json_doc
,
path
[,
path
] ...)
path
NULL
json_doc
path
path
MySQL的> SELECT JSON_EXTRACT('[10, 20, [30, 40]]', '$[1]');
|小站JSON _提取物([ 10,20,30,40 ]”,“美元[ 1 ])|小站| 20 |小站MySQL > SELECT JSON_EXTRACT('[10, 20, [30, 40]]', '$[1]', '$[0]');
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * SELECT JSON_EXTRACT('[10, 20, [30, 40]]', '$[2][*]');
Am I Json Control I ExtrAct(' [ 10,20,[ 30,40 ] ] ',' s,' $ [ 2 ] [ * ] ')
->
JSON
->
JSON_EXTRACT()
SELECT
MySQL的> SELECT c, JSON_EXTRACT(c, "$.id"), g
> FROM jemp
> WHERE JSON_EXTRACT(c, "$.id") > 1
> ORDER BY JSON_EXTRACT(c, "$.name");
+-------------------------------+-----------+------+| c | c->"$.id" | g |+-------------------------------+-----------+------+| {"id": "3", "name": "Barney"} | "3" | 3 || {"id": "4", "name": "Betty"} | "4" | 4 || {"id": "2", "name": "Wilma"} | "2" | 2 |+-------------------------------+-----------+------+3 rows in set (0.00 sec)mysql>SELECT c, c->"$.id", g
> FROM jemp
> WHERE c->"$.id" > 1
> ORDER BY c->"$.name";
------------------------------- ----------- ------ | C | C - >“美元。ID”| G | ------------------------------- ----------- ------ | {“id”:“3”,“name”:“巴尼”} |“3”| 3 | | {“id”:“4”,“name”:“贝蒂”} |“4”| 4 | | {“id”:“2”,“name”:“威尔玛”} |“2”| 2 | ------------------------------- ----------- ------ 3行集(0秒)
SELECT
MySQL的> ALTER TABLE jemp ADD COLUMN n INT;
查询好,为受影响的行(0.68秒)记录:0 0副本:警告:0mysql > UPDATE jemp SET n=1 WHERE c->"$.id" = "4";
查询行,1行的影响(0.04秒)的行匹配:1改变:1警告:0mysql > SELECT c, c->"$.id", g, n
> FROM jemp
> WHERE JSON_EXTRACT(c, "$.id") > 1
> ORDER BY c->"$.name";
+-------------------------------+-----------+------+------+| c | c->"$.id" | g | n |+-------------------------------+-----------+------+------+| {"id": "3", "name": "Barney"} | "3" | 3 | NULL || {"id": "4", "name": "Betty"} | "4" | 4 | 1 || {"id": "2", "name": "Wilma"} | "2" | 2 | NULL |+-------------------------------+-----------+------+------+3 rows in set (0.00 sec)mysql>DELETE FROM jemp WHERE c->"$.id" = "4";
查询行,1行的影响(0.04秒)MySQL > SELECT c, c->"$.id", g, n
> FROM jemp
> WHERE JSON_EXTRACT(c, "$.id") > 1
> ORDER BY c->"$.name";
------------------------------- ----------- ------ ------ | C | C - >“美元。ID”| G | N | ------------------------------- ----------- ------ ------ | {“id”:“3”,“name”:“巴尼”} |“3”| 3 |空| | {“id”:“2”,“姓名”:“威尔玛”} |“2”| 2 |空| ------------------------------- ----------- ------ ------ 2行集(0秒)
mysql>CREATE TABLE tj10 (a JSON, b INT);
Query OK, 0 rows affected (0.26 sec) mysql>INSERT INTO tj10
>VALUES ("[3,10,5,17,44]", 33), ("[3,10,5,17,[22,44,66]]", 0);
Query OK, 1 row affected (0.04 sec) mysql>SELECT a->"$[4]" FROM tj10;
+--------------+ | a->"$[4]" | +--------------+ | 44 | | [22, 44, 66] | +--------------+ 2 rows in set (0.00 sec) mysql>SELECT * FROM tj10 WHERE a->"$[0]" = 3;
+------------------------------+------+ | a | b | +------------------------------+------+ | [3, 10, 5, 17, 44] | 33 | | [3, 10, 5, 17, [22, 44, 66]] | 0 | +------------------------------+------+ 2 rows in set (0.00 sec)
->
mysql>SELECT * FROM tj10 WHERE a->"$[4][1]" IS NOT NULL;
+------------------------------+------+ | a | b | +------------------------------+------+ | [3, 10, 5, 17, [22, 44, 66]] | 0 | +------------------------------+------+ mysql>SELECT a->"$[4][1]" FROM tj10;
+--------------+ | a->"$[4][1]" | +--------------+ | NULL | | 44 | +--------------+ 2 rows in set (0.00 sec)
JSON_EXTRACT()
MySQL的> SELECT JSON_EXTRACT(a, "$[4][1]") FROM tj10;
---------------------------- | json_extract(,$ [ 4 ] [ 1 ]”)| ---------------------------- |空| | 44 | ---------------------------- 2行集(0秒)
->
->>
JSON
column
path
JSON_UNQUOTE(
column
->
path
column
->>path
->>
SELECT
HAVING
GROUP BY
->>
mysql>SELECT * FROM jemp WHERE g > 2;
+-------------------------------+------+ | c | g | +-------------------------------+------+ | {"id": "3", "name": "Barney"} | 3 | | {"id": "4", "name": "Betty"} | 4 | +-------------------------------+------+ 2 rows in set (0.01 sec) mysql>SELECT c->'$.name' AS name
->FROM jemp WHERE g > 2;
+----------+ | name | +----------+ | "Barney" | | "Betty" | +----------+ 2 rows in set (0.00 sec) mysql>SELECT JSON_UNQUOTE(c->'$.name') AS name
->FROM jemp WHERE g > 2;
+--------+ | name | +--------+ | Barney | | Betty | +--------+ 2 rows in set (0.00 sec) mysql>SELECT c->>'$.name' AS name
->FROM jemp WHERE g > 2;
+--------+ | name | +--------+ | Barney | | Betty | +--------+ 2 rows in set (0.00 sec)
jemp
mysql>CREATE TABLE tj10 (a JSON, b INT);
Query OK, 0 rows affected (0.26 sec) mysql>INSERT INTO tj10 VALUES
->('[3,10,5,"x",44]', 33),
->('[3,10,5,17,[22,"y",66]]', 0);
Query OK, 2 rows affected (0.04 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql>SELECT a->"$[3]", a->"$[4][1]" FROM tj10;
+-----------+--------------+ | a->"$[3]" | a->"$[4][1]" | +-----------+--------------+ | "x" | NULL | | 17 | "y" | +-----------+--------------+ 2 rows in set (0.00 sec) mysql>SELECT a->>"$[3]", a->>"$[4][1]" FROM tj10;
+------------+---------------+ | a->>"$[3]" | a->>"$[4][1]" | +------------+---------------+ | x | NULL | | 17 | y | +------------+---------------+ 2 rows in set (0.00 sec)
->
->>
EXPLAIN
MySQL的> EXPLAIN SELECT c->>'$.name' AS name
-> FROM jemp WHERE g > 2\G
*************************** 1。行***************************编号:1 select_type:简单表:jemp分区:null类型:rangepossible_keys:我:我key_len:5编号:零排:2过滤:额外100:用其中1行集,1报警(0秒)MySQL > SHOW WARNINGS\G
*************************** 1。行***************************水平:注意代码:1003message:/ *选择# 1 * / selectjson_unquote(json_extract(` Jtest `。` jemp `。` C `,“美元。名字))作为`名字`从` Jtest `。` jemp `哪里(` Jtest `。` jemp ` ` G `。> 2)中1行集(0秒)
->
path
NULL
json_doc
path
json_doc
path
**
mysql>SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}');
+---------------------------------------+ | JSON_KEYS('{"a": 1, "b": {"c": 30}}') | +---------------------------------------+ | ["a", "b"] | +---------------------------------------+ mysql>SELECT JSON_KEYS('{"a": 1, "b": {"c": 30}}', '$.b');
+----------------------------------------------+ | JSON_KEYS('{"a": 1, "b": {"c": 30}}', '$.b') | +----------------------------------------------+ | ["c"] | +----------------------------------------------+
JSON_SEARCH(
json_doc
,
one_or_all
,
search_str
[,
escape_char
[,
path
] ...])
NULL
json_doc
search_str
path
path
search_str
json_doc
path
one_or_all
'all'
escape_char
one_or_all
'one'
'all'
search_str
_
LIKE
_
%
\
escape_char
escape_char
LIKE
LIKE
JSON_SEARCH()
JSON_SEARCH()
escape_char
mysql>SET @j = '["abc", [{"k": "10"}, "def"], {"x":"abc"}, {"y":"bcd"}]';
mysql>SELECT JSON_SEARCH(@j, 'one', 'abc');
+-------------------------------+ | JSON_SEARCH(@j, 'one', 'abc') | +-------------------------------+ | "$[0]" | +-------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', 'abc');
+-------------------------------+ | JSON_SEARCH(@j, 'all', 'abc') | +-------------------------------+ | ["$[0]", "$[2].x"] | +-------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', 'ghi');
+-------------------------------+ | JSON_SEARCH(@j, 'all', 'ghi') | +-------------------------------+ | NULL | +-------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10');
+------------------------------+ | JSON_SEARCH(@j, 'all', '10') | +------------------------------+ | "$[1][0].k" | +------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$');
+-----------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$') | +-----------------------------------------+ | "$[1][0].k" | +-----------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$[*]');
+--------------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$[*]') | +--------------------------------------------+ | "$[1][0].k" | +--------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$**.k');
+---------------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$**.k') | +---------------------------------------------+ | "$[1][0].k" | +---------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$[*][0].k');
+-------------------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$[*][0].k') | +-------------------------------------------------+ | "$[1][0].k" | +-------------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$[1]');
+--------------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$[1]') | +--------------------------------------------+ | "$[1][0].k" | +--------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '10', NULL, '$[1][0]');
+-----------------------------------------------+ | JSON_SEARCH(@j, 'all', '10', NULL, '$[1][0]') | +-----------------------------------------------+ | "$[1][0].k" | +-----------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', 'abc', NULL, '$[2]');
+---------------------------------------------+ | JSON_SEARCH(@j, 'all', 'abc', NULL, '$[2]') | +---------------------------------------------+ | "$[2].x" | +---------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%a%');
+-------------------------------+ | JSON_SEARCH(@j, 'all', '%a%') | +-------------------------------+ | ["$[0]", "$[2].x"] | +-------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%');
+-------------------------------+ | JSON_SEARCH(@j, 'all', '%b%') | +-------------------------------+ | ["$[0]", "$[2].x", "$[3].y"] | +-------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%', NULL, '$[0]');
+---------------------------------------------+ | JSON_SEARCH(@j, 'all', '%b%', NULL, '$[0]') | +---------------------------------------------+ | "$[0]" | +---------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%', NULL, '$[2]');
+---------------------------------------------+ | JSON_SEARCH(@j, 'all', '%b%', NULL, '$[2]') | +---------------------------------------------+ | "$[2].x" | +---------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%', NULL, '$[1]');
+---------------------------------------------+ | JSON_SEARCH(@j, 'all', '%b%', NULL, '$[1]') | +---------------------------------------------+ | NULL | +---------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%', '', '$[1]');
+-------------------------------------------+ | JSON_SEARCH(@j, 'all', '%b%', '', '$[1]') | +-------------------------------------------+ | NULL | +-------------------------------------------+ mysql>SELECT JSON_SEARCH(@j, 'all', '%b%', '', '$[3]');
+-------------------------------------------+ | JSON_SEARCH(@j, 'all', '%b%', '', '$[3]') | +-------------------------------------------+ | "$[3].y" | +-------------------------------------------+
*
JSON_ARRAY_APPEND(
json_doc
,
path
,
val
[,
path
,
val
] ...)
NULL
json_doc
path
**
mysql>SET @j = '["a", ["b", "c"], "d"]';
mysql>SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1);
+----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql>SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2);
+----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]', 2) | +----------------------------------+ | [["a", 2], ["b", "c"], "d"] | +----------------------------------+ mysql>SELECT JSON_ARRAY_APPEND(@j, '$[1][0]', 3);
+-------------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1][0]', 3) | +-------------------------------------+ | ["a", [["b", 3], "c"], "d"] | +-------------------------------------+ mysql>SET @j = '{"a": 1, "b": [2, 3], "c": 4}';
mysql>SELECT JSON_ARRAY_APPEND(@j, '$.b', 'x');
+------------------------------------+ | JSON_ARRAY_APPEND(@j, '$.b', 'x') | +------------------------------------+ | {"a": 1, "b": [2, 3, "x"], "c": 4} | +------------------------------------+ mysql>SELECT JSON_ARRAY_APPEND(@j, '$.c', 'y');
+--------------------------------------+ | JSON_ARRAY_APPEND(@j, '$.c', 'y') | +--------------------------------------+ | {"a": 1, "b": [2, 3], "c": [4, "y"]} | +--------------------------------------+ mysql>SET @j = '{"a": 1}';
mysql>SELECT JSON_ARRAY_APPEND(@j, '$', 'z');
+---------------------------------+ | JSON_ARRAY_APPEND(@j, '$', 'z') | +---------------------------------+ | [{"a": 1}, "z"] | +---------------------------------+
JSON_APPEND()
JSON_ARRAY_INSERT(
json_doc
,
path
,
val
[,
path
,
val
] ...)
NULL
json_doc
path
**
mysql>SET @j = '["a", {"b": [1, 2]}, [3, 4]]';
mysql>SELECT JSON_ARRAY_INSERT(@j, '$[1]', 'x');
+------------------------------------+ | JSON_ARRAY_INSERT(@j, '$[1]', 'x') | +------------------------------------+ | ["a", "x", {"b": [1, 2]}, [3, 4]] | +------------------------------------+ mysql>SELECT JSON_ARRAY_INSERT(@j, '$[100]', 'x');
+--------------------------------------+ | JSON_ARRAY_INSERT(@j, '$[100]', 'x') | +--------------------------------------+ | ["a", {"b": [1, 2]}, [3, 4], "x"] | +--------------------------------------+ mysql>SELECT JSON_ARRAY_INSERT(@j, '$[1].b[0]', 'x');
+-----------------------------------------+ | JSON_ARRAY_INSERT(@j, '$[1].b[0]', 'x') | +-----------------------------------------+ | ["a", {"b": ["x", 1, 2]}, [3, 4]] | +-----------------------------------------+ mysql>SELECT JSON_ARRAY_INSERT(@j, '$[2][1]', 'y');
+---------------------------------------+ | JSON_ARRAY_INSERT(@j, '$[2][1]', 'y') | +---------------------------------------+ | ["a", {"b": [1, 2]}, [3, "y", 4]] | +---------------------------------------+ mysql>SELECT JSON_ARRAY_INSERT(@j, '$[0]', 'x', '$[2][1]', 'y');
+----------------------------------------------------+ | JSON_ARRAY_INSERT(@j, '$[0]', 'x', '$[2][1]', 'y') | +----------------------------------------------------+ | ["x", "a", {"b": [1, 2]}, [3, 4]] | +----------------------------------------------------+
JSON_ARRAY_INSERT()
JSON_INSERT(
json_doc
,
path
,
val
[,
path
,
val
] ...)
NULL
json_doc
path
**
JSON_INSERT()
JSON_REPLACE()
JSON_SET()
JSON_SET()
MySQL的> SET @j = '{ "a": 1, "b": [2, 3]}';
MySQL的> SELECT JSON_INSERT(@j, '$.a', 10, '$.c', '[true, false]');
---------------------------------------------------- | JSON _ insert(@美元J,T,C,10美元,是真是假,[,])| ---------------------------------------------------- | {“a”:1、“B”:[ 2,3 ],“C”:“[假]真的,”| ---------------------------------------------------- }
mysql> SELECT JSON_INSERT(@j, '$.a', 10, '$.c', CAST('[true, false]' AS JSON));
+------------------------------------------------------------------+
| JSON_INSERT(@j, '$.a', 10, '$.c', CAST('[true, false]' AS JSON)) |
+------------------------------------------------------------------+
| {"a": 1, "b": [2, 3], "c": [true, false]} |
+------------------------------------------------------------------+
1 row in set (0.00 sec)
JSON_MERGE(
json_doc
,
json_doc
[,
json_doc
] ...)
JSON_MERGE_PRESERVE()
MySQL的> SELECT JSON_MERGE('[1, 2]', '[true, false]');
| --------------------------------------- JSON _ MERGE(〔1,2〕,〔〕是真是假,| --------------------------------------- |)〔1,2〕,真实,虚假| --------------------------------------- 1行集(0秒)1预警,数据库 SHOW WARNINGS\G
*************************** 1。行***************************水平:报警代码:1287message:“json_merge是过时的、将在未来的版本中删除。请使用json_merge_preserve / json_merge_patch instead1行集(0秒)
JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH(
json_doc
,
json_doc
[,
json_doc
] ...)
JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH()
null
null
mysql>SELECT JSON_MERGE_PATCH('[1, 2]', '[true, false]');
+---------------------------------------------+ | JSON_MERGE_PATCH('[1, 2]', '[true, false]') | +---------------------------------------------+ | [true, false] | +---------------------------------------------+ mysql>SELECT JSON_MERGE_PATCH('{"name": "x"}', '{"id": 47}');
+-------------------------------------------------+ | JSON_MERGE_PATCH('{"name": "x"}', '{"id": 47}') | +-------------------------------------------------+ | {"id": 47, "name": "x"} | +-------------------------------------------------+ mysql>SELECT JSON_MERGE_PATCH('1', 'true');
+-------------------------------+ | JSON_MERGE_PATCH('1', 'true') | +-------------------------------+ | true | +-------------------------------+ mysql>SELECT JSON_MERGE_PATCH('[1, 2]', '{"id": 47}');
+------------------------------------------+ | JSON_MERGE_PATCH('[1, 2]', '{"id": 47}') | +------------------------------------------+ | {"id": 47} | +------------------------------------------+ mysql>SELECT JSON_MERGE_PATCH('{ "a": 1, "b":2 }',
>'{ "a": 3, "c":4 }');
+-----------------------------------------------------------+ | JSON_MERGE_PATCH('{ "a": 1, "b":2 }','{ "a": 3, "c":4 }') | +-----------------------------------------------------------+ | {"a": 3, "b": 2, "c": 4} | +-----------------------------------------------------------+ mysql>SELECT JSON_MERGE_PATCH('{ "a": 1, "b":2 }','{ "a": 3, "c":4 }',
>'{ "a": 5, "d":6 }');
+-------------------------------------------------------------------------------+ | JSON_MERGE_PATCH('{ "a": 1, "b":2 }','{ "a": 3, "c":4 }','{ "a": 5, "d":6 }') | +-------------------------------------------------------------------------------+ | {"a": 5, "b": 2, "c": 4, "d": 6} | +-------------------------------------------------------------------------------+
null
MySQL的> SELECT JSON_MERGE_PATCH('{"a":1, "b":2}', '{"b":null}');
-------------------------------------------------- | JSON _ MERGE _补丁(“A”:{1,2}:“b”,“B”:空{ }){“a”| -------------------------------------------------- | | -------------------------------------------------- 1 }:
mysql> SELECT JSON_MERGE_PATCH('{"a":{"x":1}}', '{"a":{"y":2}}');
+----------------------------------------------------+
| JSON_MERGE_PATCH('{"a":{"x":1}}', '{"a":{"y":2}}') |
+----------------------------------------------------+
| {"a": {"x": 1, "y": 2}} |
+----------------------------------------------------+
JSON_MERGE_PATCH()
JSON_MERGE_PATCH()
JSON_MERGE_PRESERVE()
JSON_MERGE_PATCH()
JSON_MERGE_PATCH()
JSON_MERGE_PRESERVE()
"a"
MySQL的> SET @x = '{ "a": 1, "b": 2 }',
> @y = '{ "a": 3, "c": 4 }',
> @z = '{ "a": 5, "d": 6 }';
MySQL的> SELECT JSON_MERGE_PATCH(@x, @y, @z) AS Patch,
-> JSON_MERGE_PRESERVE(@x, @y, @z) AS Preserve\G
*************************** 1。行***************************补丁:{“”:5,“B”:2,“C”:4,“D”:6 }保存:{“”:[ 1,3,5 ],“B”:2,“C”:4,“D”:6 }
JSON_MERGE_PRESERVE(
json_doc
,
json_doc
[,
json_doc
] ...)
NULL
mysql>SELECT JSON_MERGE_PRESERVE('[1, 2]', '[true, false]');
+------------------------------------------------+ | JSON_MERGE_PRESERVE('[1, 2]', '[true, false]') | +------------------------------------------------+ | [1, 2, true, false] | +------------------------------------------------+ mysql>SELECT JSON_MERGE_PRESERVE('{"name": "x"}', '{"id": 47}');
+----------------------------------------------------+ | JSON_MERGE_PRESERVE('{"name": "x"}', '{"id": 47}') | +----------------------------------------------------+ | {"id": 47, "name": "x"} | +----------------------------------------------------+ mysql>SELECT JSON_MERGE_PRESERVE('1', 'true');
+----------------------------------+ | JSON_MERGE_PRESERVE('1', 'true') | +----------------------------------+ | [1, true] | +----------------------------------+ mysql>SELECT JSON_MERGE_PRESERVE('[1, 2]', '{"id": 47}');
+---------------------------------------------+ | JSON_MERGE_PRESERVE('[1, 2]', '{"id": 47}') | +---------------------------------------------+ | [1, 2, {"id": 47}] | +---------------------------------------------+ mysql>SELECT JSON_MERGE_PRESERVE('{ "a": 1, "b": 2 }',
>'{ "a": 3, "c": 4 }');
+--------------------------------------------------------------+ | JSON_MERGE_PRESERVE('{ "a": 1, "b": 2 }','{ "a": 3, "c":4 }') | +--------------------------------------------------------------+ | {"a": [1, 3], "b": 2, "c": 4} | +--------------------------------------------------------------+ mysql>SELECT JSON_MERGE_PRESERVE('{ "a": 1, "b": 2 }','{ "a": 3, "c": 4 }',
>'{ "a": 5, "d": 6 }');
+----------------------------------------------------------------------------------+ | JSON_MERGE_PRESERVE('{ "a": 1, "b": 2 }','{ "a": 3, "c": 4 }','{ "a": 5, "d": 6 }') | +----------------------------------------------------------------------------------+ | {"a": [1, 3, 5], "b": 2, "c": 4, "d": 6} | +----------------------------------------------------------------------------------+
JSON_MERGE()
JSON_MERGE_PATCH()
JSON_REMOVE(
json_doc
,
path
[,
path
] ...)
NULL
json_doc
path
*
path
mysql>SET @j = '["a", ["b", "c"], "d"]';
mysql>SELECT JSON_REMOVE(@j, '$[1]');
+-------------------------+ | JSON_REMOVE(@j, '$[1]') | +-------------------------+ | ["a", "d"] | +-------------------------+
JSON_REPLACE(
json_doc
,
path
,
val
[,
path
,
val
] ...)
NULL
json_doc
path
**
JSON
JSON_REPLACE()
JSON_INSERT()
JSON_REPLACE()
JSON_SET()
JSON_SET()
MySQL的> SET @j = '{ "a": 1, "b": [2, 3]}';
MySQL的> SELECT JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]');
| ----------------------------------------------------- JSON _ replace(@美元J,T,C,10美元,是真是假,[,])| ----------------------------------------------------- | {:“10”,“B”:〔2,3〕}| -----------------------------------------------------
JSON_SET(
json_doc
,
path
,
val
[,
path
,
val
] ...)
NULL
path
json_doc
path
**
JSON
JSON_SET()
JSON_SET()
JSON_INSERT()
JSON_REPLACE()
JSON_SET()
JSON_INSERT()
JSON_REPLACE()
$.a
mysql>SET @j = '{ "a": 1, "b": [2, 3]}';
mysql>SELECT JSON_SET(@j, '$.a', 10, '$.c', '[true, false]');
+-------------------------------------------------+ | JSON_SET(@j, '$.a', 10, '$.c', '[true, false]') | +-------------------------------------------------+ | {"a": 10, "b": [2, 3], "c": "[true, false]"} | +-------------------------------------------------+ mysql>SELECT JSON_INSERT(@j, '$.a', 10, '$.c', '[true, false]');
+----------------------------------------------------+ | JSON_INSERT(@j, '$.a', 10, '$.c', '[true, false]') | +----------------------------------------------------+ | {"a": 1, "b": [2, 3], "c": "[true, false]"} | +----------------------------------------------------+ mysql>SELECT JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]');
+-----------------------------------------------------+ | JSON_REPLACE(@j, '$.a', 10, '$.c', '[true, false]') | +-----------------------------------------------------+ | {"a": 10, "b": [2, 3]} | +-----------------------------------------------------+
utf8mb4
NULL
NO_BACKSLASH_ESCAPES
\x
\b
B
mysql>SET @j = '"abc"';
mysql>SELECT @j, JSON_UNQUOTE(@j);
+-------+------------------+ | @j | JSON_UNQUOTE(@j) | +-------+------------------+ | "abc" | abc | +-------+------------------+ mysql>SET @j = '[1, 2, 3]';
mysql>SELECT @j, JSON_UNQUOTE(@j);
+-----------+------------------+ | @j | JSON_UNQUOTE(@j) | +-----------+------------------+ | [1, 2, 3] | [1, 2, 3] | +-----------+------------------+
JSON_UNQUOTE
NO_BACKSLASH_ESCAPES
MySQL的> SELECT @@sql_mode;
------------ | @ @ sql_mode | ------------ | | ------------ MySQL > SELECT JSON_UNQUOTE('"\\t\\u0032"');
------------------------------ | JSON _ unquote(“T u0032 \\ \\”)| ------------------------------ | ------------------------------ MySQL |>2 SET @@sql_mode = 'NO_BACKSLASH_ESCAPES';
MySQL的> SELECT JSON_UNQUOTE('"\\t\\u0032"');
------------------------------ | JSON _ unquote(“T u0032 \\ \\”)| ------------------------------ | t\ u0032 | > ------------------------------ MySQL SELECT JSON_UNQUOTE('"\t\u0032"');
JSON(_ unquote | ----------------------------“t\ u0032”2)| ---------------------------- | | ----------------------------
NULL
mysql>SELECT JSON_DEPTH('{}'), JSON_DEPTH('[]'), JSON_DEPTH('true');
+------------------+------------------+--------------------+ | JSON_DEPTH('{}') | JSON_DEPTH('[]') | JSON_DEPTH('true') | +------------------+------------------+--------------------+ | 1 | 1 | 1 | +------------------+------------------+--------------------+ mysql>SELECT JSON_DEPTH('[10, 20]'), JSON_DEPTH('[[], {}]');
+------------------------+------------------------+ | JSON_DEPTH('[10, 20]') | JSON_DEPTH('[[], {}]') | +------------------------+------------------------+ | 2 | 2 | +------------------------+------------------------+ mysql>SELECT JSON_DEPTH('[10, {"a": 20}]');
+-------------------------------+ | JSON_DEPTH('[10, {"a": 20}]') | +-------------------------------+ | 3 | +-------------------------------+
path
NULL
path
json_doc
path
**
mysql>SELECT JSON_LENGTH('[1, 2, {"a": 3}]');
+---------------------------------+ | JSON_LENGTH('[1, 2, {"a": 3}]') | +---------------------------------+ | 3 | +---------------------------------+ mysql>SELECT JSON_LENGTH('{"a": 1, "b": {"c": 30}}');
+-----------------------------------------+ | JSON_LENGTH('{"a": 1, "b": {"c": 30}}') | +-----------------------------------------+ | 2 | +-----------------------------------------+ mysql>SELECT JSON_LENGTH('{"a": 1, "b": {"c": 30}}', '$.b');
+------------------------------------------------+ | JSON_LENGTH('{"a": 1, "b": {"c": 30}}', '$.b') | +------------------------------------------------+ | 1 | +------------------------------------------------+
utf8mb4
MySQL的> SET @j = '{"a": [10, true]}';
MySQL的> SELECT JSON_TYPE(@j);
———————————————————————————————————— SELECT JSON_TYPE(JSON_EXTRACT(@j, '$.a'));
------------------------------------ | json_type(json_extract(“J”美元。'))| ------------------------------------ |阵列| ------------------------------------ MySQL > SELECT JSON_TYPE(JSON_EXTRACT(@j, '$.a[0]'));
Json Json Type(Json Cooperation Extrat(@ j,$ . a [ 0 ])ention of the United Nations Environment Proceedings SELECT JSON_TYPE(JSON_EXTRACT(@j, '$.a[1]'));
我的意思是,我的意思是,我的意思是…………………………………
JSON_TYPE()
NULL
MySQL的> SELECT JSON_TYPE(NULL);
--------------------- | JSON _型零(零)| --------------------- | | ---------------------
mysql> SELECT JSON_TYPE(1);
ERROR 3146 (22032): Invalid data type for JSON data in argument 1
to function json_type; a JSON string or JSON type is required.
NULL
JSON_TYPE()
OBJECT
ARRAY
BOOLEAN
NULL
OPAQUE
NULL
mysql>SELECT JSON_VALID('{"a": 1}');
+------------------------+ | JSON_VALID('{"a": 1}') | +------------------------+ | 1 | +------------------------+ mysql>SELECT JSON_VALID('hello'), JSON_VALID('"hello"');
+---------------------+-----------------------+ | JSON_VALID('hello') | JSON_VALID('"hello"') | +---------------------+-----------------------+ | 0 | 1 | +---------------------+-----------------------+
JSON_TABLE()
JSON_TABLE(
expr
,
path
COLUMNS
(column_list
) [AS]
alias
)
JSON_TABLE(expr
,path
COLUMNS (column_list
) ) [AS]alias
column_list
:column
[,column
][, ...]column
:name
FOR ORDINALITY |name
type
PATHstring path
[on_error
] [on_empty
] |name
type
EXISTS PATHstring path
| NESTED [PATH]path
COLUMNS (column_list
)on_error
: {NULL | ERROR | DEFAULTjson_string
} ON ERRORon_empty
: {NULL | ERROR | DEFAULTjson_string
} ON EMPTY
expr
t1.jsson_data
JSON_TABLE()
JSON_EXTRACT(t1,jsn_data,'$.post.comments')
path
COLUMNS
alias
JSON_TABLE()
name
FOR
ORDINALITYname
AUTO_INCREMENT
CREATE TABLE
name
type
PATH
string_path
[on_error
]
[on_empty
]string_path
type
on error
on_empty
on_error
NULL ON ERROR
ERROR ON ERROR
DEFAULT
json
string
ON ERRORjson_string
DECIMAL(10,1)
on empty
NESTED
PATH
on empty
NULL ON EMPTY
ERROR ON EMPTY
DEFAULT
json_string
ON
EMPTYjson_string
ON
ERROR
{"b":1}
[1,2]
MySQL的> SELECT *
-> FROM
-> JSON_TABLE(
-> '[{"a":"3"},{"a":2},{"b":1},{"a":0},{"a":[1,2]}]',
-> "$[*]"
-> COLUMNS(
-> rowid FOR ORDINALITY,
-> ac VARCHAR(100) PATH "$.a" DEFAULT '999' ON ERROR DEFAULT '111' ON EMPTY,
-> aj JSON PATH "$.a" DEFAULT '{"x": 333}' ON EMPTY,
-> bx INT EXISTS PATH "$.b"
-> )
-> ) AS tt;
------- ------ ------------ ------ | rowid |交流| AJ | BX | ------- ------ ------------ ------ | 1 | 3 |“3”| 0 | | 2 2 2 0 | | | | | 3 | | { 111 }“X”:333 | 1 | | 4 0 0 0 | | | | | 5 | 999 | [ 1, 2 ] | 0 | ------- ------ ------------ ------五行集(0.001秒)
name
type
EXISTS PATH
path
path
type
INT
NESTED [PATH]
path
COLUMNS
(column_list
)
path
NESTED [PATH]
path
mysql>SELECT *
->FROM
->JSON_TABLE(
->'[{"x":2,"y":"8"},{"x":"3","y":"7"},{"x":"4","y":6}]',
->"$[*]" COLUMNS(
->xval VARCHAR(100) PATH "$.x",
->yval VARCHAR(100) PATH "$.y"
->)
->) AS jt1;
+------+------+ | xval | yval | +------+------+ | 2 | 8 | | 3 | 7 | | 4 | 6 | +------+------+
"$[*]"
mysql>SELECT *
->FROM
->JSON_TABLE(
->'[{"x":2,"y":"8"},{"x":"3","y":"7"},{"x":"4","y":6}]',
->"$[1]" COLUMNS(
->xval VARCHAR(100) PATH "$.x",
->yval VARCHAR(100) PATH "$.y"
->)
->) AS jt1;
+------+------+ | xval | yval | +------+------+ | 3 | 7 | +------+------+
"$"
"$.y"
y
NESTED PATH
PATH
NULL
WHERE
MySQL的> SELECT *
-> FROM
-> JSON_TABLE(
-> '[ {"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]',
-> '$[*]' COLUMNS(
-> a INT PATH '$.a',
-> NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$')
-> )
-> ) AS jt
-> WHERE b IS NOT NULL;
????????????B |的| | | 1 | 11 | | 1 | 111 | | 2 | 22 | | 2 | 222 |??????
NESTED [PATH]
NULL
NESTED
[PATH]
MySQL的> SELECT *
-> FROM
-> JSON_TABLE(
-> '[{"a": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}]',
-> '$[*]' COLUMNS(
-> a INT PATH '$.a',
-> NESTED PATH '$.b[*]' COLUMNS (b1 INT PATH '$'),
-> NESTED PATH '$.b[*]' COLUMNS (b2 INT PATH '$')
-> )
-> ) AS jt;
| ------ ------ A B1 B2 | ------ | | ------ ------ ------ | 1 11 1 | |零| | | 111 |零零| | | | 1 11 1 | | |零| 111 | | | 22 2 2 |零| | | 222 |零| | |零| | | 22 2 2 |零| 222 | ------ ------。
FOR ORDINALITY
mysql>SELECT *
->FROM
->JSON_TABLE(
->'[{"a": "a_val",
'>"b": [{"c": "c_val", "l": [1,2]}]},
'>{"a": "a_val",
'>"b": [{"c": "c_val","l": [11]}, {"c": "c_val", "l": [22]}]}]',
->'$[*]' COLUMNS(
->top_ord FOR ORDINALITY,
->apath VARCHAR(10) PATH '$.a',
->NESTED PATH '$.b[*]' COLUMNS (
->bpath VARCHAR(10) PATH '$.c',
->ord FOR ORDINALITY,
->NESTED PATH '$.l[*]' COLUMNS (lpath varchar(10) PATH '$')
->)
->)
->) as jt;
+---------+---------+---------+------+-------+ | top_ord | apath | bpath | ord | lpath | +---------+---------+---------+------+-------+ | 1 | a_val | c_val | 1 | 1 | | 1 | a_val | c_val | 1 | 2 | | 2 | a_val | c_val | 1 | 11 | | 2 | a_val | c_val | 2 | 22 | +---------+---------+---------+------+-------+
apath
lpath
top_ord
JSON_PRETTY()
JSON_STORAGE_SIZE()
JSON_STORAGE_FREE()
NULL
:
JSON_QUOTE()
MySQL的> SELECT JSON_PRETTY('123'); # scalar
漂亮的| JSON _ -----------------------(123)| -------------------- | 123 | -------------------- MySQL > SELECT JSON_PRETTY("[1,3,5]"); # array
------------------------ | JSON _漂亮(“[ 1 ]”)| ------------------------ | [ 1,3,5 ] | ------------------------ MySQL > SELECT JSON_PRETTY('{"a":"10","b":"15","x":"25"}'); # object
--------------------------------------------- _漂亮| JSON(“{“a”:“10”、“B”:“十五”、“X”:“25”“{ }”| | ---------------------------------------------)”:“10”、“B”:“十五”、“X”| --------------------------------------------- }:“25”MySQL > SELECT JSON_PRETTY('["a",1,{"key1":
> "value1"},"5", "77" ,
> {"key2":["value3","valueX",
> "valueY"]},"j", "2" ]')\G # nested arrays and objects
* * * * * * * * * * * * * * * * * * * * * * * * * * * 1。行* * * * * * * * * * * * * * * * * * * * * * * * * * * *(JSON _〔1“,”,“{ }”KEY1”:value1”、“5”、“77”,{“[ key2”:“value3”、“valuex”、“valuey”] },“J”,“2”是:[ ]),“1”,在“{ }”KEY1”:value1”、“5”、“77”,{“[”value3 key2”:“,,”valuex”“valuey ]“,”2“,”J”]
JSON
JSON_SET()
JSON_REPLACE()
JSON_REMOVE()
JSON
NULL
json_val
JSON
MySQL的> CREATE TABLE jtable (jcol JSON);
查询行,0行受影响(0.38秒)MySQL > INSERT INTO jtable VALUES
-> ('{"a": 10, "b": "wxyz", "c": "[true, false]"}');
查询行,1行的影响(0.04秒)MySQL > SELECT * FROM jtable;
---------------------------------------------- | jcol | ---------------------------------------------- | {“,”10“,”B“,”wxyz:“C”:“[假]真的,”| ---------------------------------------------- } 1行集(0秒)
JSON_SET()
[true,
false]
mysql>UPDATE jtable
->SET jcol = JSON_SET(jcol, "$.a", 10, "$.b", "wxyz", "$.c", 1);
Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>SELECT * FROM jtable;
+--------------------------------+ | jcol | +--------------------------------+ | {"a": 10, "b": "wxyz", "c": 1} | +--------------------------------+ 1 row in set (0.00 sec) mysql>SELECT JSON_STORAGE_FREE(jcol) FROM jtable;
+-------------------------+ | JSON_STORAGE_FREE(jcol) | +-------------------------+ | 14 | +-------------------------+ 1 row in set (0.00 sec)
JSON_SET()
mysql>UPDATE jtable
->SET jcol = JSON_SET(jcol, "$.a", 10, "$.b", "wx", "$.c", 1);
Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>SELECT JSON_STORAGE_FREE(jcol) FROM jtable;
+-------------------------+ | JSON_STORAGE_FREE(jcol) | +-------------------------+ | 16 | +-------------------------+ 1 row in set (0.00 sec)
JSON_SET()
JSON_REMOVE()
mysql>UPDATE jtable SET jcol = '{"a": 10, "b": 1}';
Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>SELECT JSON_STORAGE_FREE(jcol) FROM jtable;
+-------------------------+ | JSON_STORAGE_FREE(jcol) | +-------------------------+ | 0 | +-------------------------+ 1 row in set (0.00 sec)
JSON_SET()
MySQL的> SET @j = '{"a": 10, "b": "wxyz", "c": "[true, false]"}';
查询好,为受影响的行(0.001秒)MySQL > SET @j = JSON_SET(@j, '$.a', 10, '$.b', 'wxyz', '$.c', '1');
查询好,为受影响的行(0.001秒)MySQL > SELECT @j, JSON_STORAGE_FREE(@j) AS Free;
---------------------------------- ------ | @ J |自由| ---------------------------------- ------ | {“”:,“B”:“wxyz”、“C”:“”} | 0 | ---------------------------------- ------一行集(0.001秒)
mysql> SELECT JSON_STORAGE_FREE('{"a": 10, "b": "wxyz", "c": "1"}') AS Free;
+------+
| Free |
+------+
| 0 |
+------+
1 row in set (0.00 sec)
JSON
json_val
NULL
json_val
JSON
JSON
JSON_STORAGE_SIZE()
MySQL的> CREATE TABLE jtable (jcol JSON);
查询行,0行受影响(0.42秒)MySQL > INSERT INTO jtable VALUES
-> ('{"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"}');
查询行,1行的影响(0.04秒)MySQL > SELECT
-> jcol,
-> JSON_STORAGE_SIZE(jcol) AS Size,
-> JSON_STORAGE_FREE(jcol) AS Free
-> FROM jtable;
----------------------------------------------- ------ ------ | jcol |大小|自由| ----------------------------------------------- ------ ------ | {“”:一千,“B”:“wxyz”、“C”:“[ 1,3,5,7 ]”} | 47 | 0 | ----------------------------------------------- ------ ------一行集(0.001秒)
JSON_STORAGE_SIZE()
JSON_STORAGE_FREE()
UPDATE
mysql>UPDATE jtable SET jcol =
->JSON_SET(jcol, "$.b", "a");
Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql>SELECT
->jcol,
->JSON_STORAGE_SIZE(jcol) AS Size,
->JSON_STORAGE_FREE(jcol) AS Free
->FROM jtable;
+--------------------------------------------+------+------+ | jcol | Size | Free | +--------------------------------------------+------+------+ | {"a": 1000, "b": "a", "c": "[1, 3, 5, 7]"} | 47 | 3 | +--------------------------------------------+------+------+ 1 row in set (0.00 sec)
JSON_STORAGE_FREE()
JSON_SET()
JSON_REPLACE()
JSON_REMOVE()
JSON_STORAGE_SIZE()
MySQL的> UPDATE jtable
MySQL的> SET jcol = '{"a": 4.55, "b": "wxyz", "c": "[true, false]"}';
查询行,1行的影响(0.04秒)的行匹配:1改变:1警告:0mysql > SELECT
-> jcol,
-> JSON_STORAGE_SIZE(jcol) AS Size,
-> JSON_STORAGE_FREE(jcol) AS Free
-> FROM jtable;
------------------------------------------------ ------ ------ | jcol |大小|自由| ------------------------------------------------ ------ ------ | {“”:4.55,“B”:“wxyz”、“C”:“[真、假]”} | 56 | 0 | ------------------------------------------------ ------ ------ 1行集(0秒)
mysql>SET @j = '[100, "sakila", [1, 3, 5], 425.05]';
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @j, JSON_STORAGE_SIZE(@j) AS Size;
+------------------------------------+------+ | @j | Size | +------------------------------------+------+ | [100, "sakila", [1, 3, 5], 425.05] | 45 | +------------------------------------+------+ 1 row in set (0.00 sec) mysql>SET @j = JSON_SET(@j, '$[1]', "json");
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @j, JSON_STORAGE_SIZE(@j) AS Size;
+----------------------------------+------+ | @j | Size | +----------------------------------+------+ | [100, "json", [1, 3, 5], 425.05] | 43 | +----------------------------------+------+ 1 row in set (0.00 sec) mysql>SET @j = JSON_SET(@j, '$[2][0]', JSON_ARRAY(10, 20, 30));
Query OK, 0 rows affected (0.00 sec) mysql>SELECT @j, JSON_STORAGE_SIZE(@j) AS Size;
+---------------------------------------------+------+ | @j | Size | +---------------------------------------------+------+ | [100, "json", [[10, 20, 30], 3, 5], 425.05] | 56 | +---------------------------------------------+------+ 1 row in set (0.00 sec)
mysql>SELECT
->JSON_STORAGE_SIZE('[100, "sakila", [1, 3, 5], 425.05]') AS A,
->JSON_STORAGE_SIZE('{"a": 1000, "b": "a", "c": "[1, 3, 5, 7]"}') AS B,
->JSON_STORAGE_SIZE('{"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"}') AS C,
->JSON_STORAGE_SIZE('[100, "json", [[10, 20, 30], 3, 5], 425.05]') AS D;
+----+----+----+----+ | A | B | C | D | +----+----+----+----+ | 45 | 44 | 47 | 56 | +----+----+----+----+ 1 row in set (0.00 sec)
$
[
N
]N
ascii
utf8mb4
pathExpression
:scope
[(pathLeg
)*]pathLeg
:member
|arrayLocation
|doubleAsterisk
member
:period
(keyName
|asterisk
)arrayLocation
:leftBracket
(nonNegativeInteger
|asterisk
)rightBracket
keyName
:ESIdentifier
|doubleQuotedString
doubleAsterisk
: '**'period
: '.'asterisk
: '*'leftBracket
: '['rightBracket
: ']'
$
*
.*
[*]
[
prefix
]**suffix
prefix
suffix
prefix
suffix
***
JSON_CONTAINS_PATH()
JSON_SET()
JSON_REPLACE()
**
JSON_SEARCH()
CREATE FUNCTION GTID_UNION(g1 TEXT, g2 TEXT) RETURNS TEXT DETERMINISTIC RETURN CONCAT(g1,',',g2);
GTID_SUBSET() | |
GTID_SUBTRACT() | |
WAIT_FOR_EXECUTED_GTID_SET() | |
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS() |
subset
set
subset
set
mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 1 1 row in set (0.00 sec) mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23-25',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23-25', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 1 1 row in set (0.00 sec) mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 0 1 row in set (0.00 sec)
subset
set
set
subset
mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:22-57 1 row in set (0.00 sec) mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:26-57 1 row in set (0.00 sec) mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:21-22:25-57 1 row in set (0.01 sec)
WAIT_FOR_EXECUTED_GTID_SET(
gtid_set
[,
timeout
])
gtid_set
gtid_subset
timeout
timeout
WAIT_FOR_EXECUTED_GTID_SET()
mysql> SELECT WAIT_FOR_EXECUTED_GTID_SET('3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5');
-> 0
WAIT_FOR_EXECUTED_GTID_SET()
gtid_mode
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(
gtid_set
[,
timeout
][,channel
])
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
gtid_set
timeout
WAIT_FOR_EXECUTED_GTID_SET()
channel
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
gtid_mode
gtid_mode
plugin_dir
openssl_udf.so
CREATE
FUNCTION
创建函数返回字符串asymmetric_decrypt现在的openssl_udf。所以;创建功能asymmetric_derive返回字符串的openssl_udf现在。所以;创建功能asymmetric_encrypt返回字符串的openssl_udf现在。所以;创建功能asymmetric_sign返回字符串的openssl_udf现在。所以;创建函数返回整数asymmetric_verify现在的openssl_udf。所以创造create_asymmetric_priv_key返回功能;现在openssl_udf字符串',';创建功能create_asymmetric_pub_key返回字符串的openssl_udf现在。所以;创建功能create_dh_parameters返回字符串的openssl_udf现在。所以;创建功能create_digest返回字符串的openssl_udf现在。”;
DROP
FUNCTION
create_asymmetric_priv_key降功能create_asymmetric_pub_key下降功能;
CREATE
FUNCTION
DROP
FUNCTION
CREATE
FUNCTION
DROP
FUNCTION
INSERT
DROP
-- Encryption algorithm; can be 'DSA' or 'DH' instead SET @algo = 'RSA'; -- Key length in bits; make larger for stronger keys SET @key_len = 1024; -- Create private key SET @priv = CREATE_ASYMMETRIC_PRIV_KEY(@algo, @key_len); -- Derive corresponding public key from private key, using same algorithm SET @pub = CREATE_ASYMMETRIC_PUB_KEY(@algo, @priv);
SET @ciphertext = ASYMMETRIC_ENCRYPT(@algo, 'My secret text', @priv); SET @cleartext = ASYMMETRIC_DECRYPT(@algo, @ciphertext, @pub);
SET @ciphertext = ASYMMETRIC_ENCRYPT(@algo, 'My secret text', @pub); SET @cleartext = ASYMMETRIC_DECRYPT(@algo, @ciphertext, @priv);
-- Digest type; can be 'SHA256', 'SHA384', or 'SHA512' instead SET @dig_type = 'SHA224'; -- Generate digest string SET @dig = CREATE_DIGEST(@dig_type, 'My text to digest');
-- Encryption algorithm; could be 'DSA' instead; keys must -- have been created using same algorithm SET @algo = 'RSA'; -- Generate signature for digest and verify signature against digest SET @sig = ASYMMETRIC_SIGN(@algo, @dig, @priv, @dig_type); -- Verify signature against digest SET @verf = ASYMMETRIC_VERIFY(@algo, @dig, @sig, @pub, @dig_type);
CREATE_DH_PARAMETERS()
CREATE_ASYMMETRIC_PRIV_KEY()
-- Generate DH shared symmetric secretSET @dhp = CREATE_DH_PARAMETERS(1024);-- Generate DH key pairsSET @algo = 'DH';SET @priv1 = CREATE_ASYMMETRIC_PRIV_KEY(@algo, @dhp);SET @pub1 = CREATE_ASYMMETRIC_PUB_KEY(@algo, @priv1);SET @priv2 = CREATE_ASYMMETRIC_PRIV_KEY(@algo, @dhp);SET @pub2 = CREATE_ASYMMETRIC_PUB_KEY(@algo, @priv2);-- Generate symmetric key using public key of first party,-- private key of second partySET @sym1 = ASYMMETRIC_DERIVE(@pub1, @priv2);-- Or use public key of second party, private key of first partySET @sym2 = ASYMMETRIC_DERIVE(@pub2, @priv1);
SET
SELECT
INSERT
SET @priv1 = CREATE_ASYMMETRIC_PRIV_KEY('RSA', 1024);SELECT CREATE_ASYMMETRIC_PRIV_KEY('RSA', 1024) INTO @priv2;INSERT INTO t (key_col) VALUES(CREATE_ASYMMETRIC_PRIV_KEY('RSA', 1024));
LOAD_FILE()
FILE
CREATE_ASYMMETRIC_PRIV_KEY()
CREATE_DH_PARAMETERS()
CREATE_ASYMMETRIC_PRIV_KEY()
CREATE_DH_PARAMETERS()
MYSQL_OPENSSL_UDF_DSA_BITS_THRESHOLD
CREATE_ASYMMETRIC_PRIV_KEY()
MYSQL_OPENSSL_UDF_RSA_BITS_THRESHOLD
CREATE_ASYMMETRIC_PRIV_KEY()
MYSQL_OPENSSL_UDF_DH_BITS_THRESHOLD
CREATE_DH_PARAMETERS()
CREATE_ASYMMETRIC_PRIV_KEY()
export MYSQL_OPENSSL_UDF_DSA_BITS_THRESHOLD=4096export MYSQL_OPENSSL_UDF_RSA_BITS_THRESHOLD=4096
ASYMMETRIC_DECRYPT() | |
ASYMMETRIC_DERIVE() | |
ASYMMETRIC_ENCRYPT() | |
ASYMMETRIC_SIGN() | |
ASYMMETRIC_VERIFY() | |
CREATE_ASYMMETRIC_PRIV_KEY() | |
CREATE_ASYMMETRIC_PUB_KEY() | |
CREATE_DH_PARAMETERS() | |
CREATE_DIGEST() |
NULL
ASYMMETRIC_DECRYPT() | |
ASYMMETRIC_DERIVE() | |
ASYMMETRIC_ENCRYPT() | |
ASYMMETRIC_SIGN() | |
ASYMMETRIC_VERIFY() | |
CREATE_ASYMMETRIC_PRIV_KEY() | |
CREATE_ASYMMETRIC_PUB_KEY() | |
CREATE_DH_PARAMETERS() |
ASYMMETRIC_ENCRYPT()
ASYMMETRIC_DECRYPT()
ASYMMETRIC_DECRYPT(
algorithm
,
crypt_str
,
key_str
)
NULL
key_str
ASYMMETRIC_ENCRYPT()
algorithm
algorithm
ASYMMETRIC_ENCRYPT()
ASYMMETRIC_DERIVE(
pub_key_str
,
priv_key_str
)
NULL
pub_key_str
priv_key_str
SET @dhp = CREATE_DH_PARAMETERS(1024); SET @priv1 = CREATE_ASYMMETRIC_PRIV_KEY('DH', @dhp); SET @pub1 = CREATE_ASYMMETRIC_PUB_KEY('DH', @priv1); SET @priv2 = CREATE_ASYMMETRIC_PRIV_KEY('DH', @dhp); SET @pub2 = CREATE_ASYMMETRIC_PUB_KEY('DH', @priv2);
ASYMMETRIC_DERIVE(@pub1, @priv2) = ASYMMETRIC_DERIVE(@pub2, @priv1)
ASYMMETRIC_ENCRYPT(
algorithm
,
str
,
key_str
)
NULL
str
key_str
key_str
algorithm
algorithm
ASYMMETRIC_ENCRYPT()
ASYMMETRIC_DECRYPT()
-- Generate private/public key pairSET @priv = CREATE_ASYMMETRIC_PRIV_KEY('RSA', 1024);SET @pub = CREATE_ASYMMETRIC_PUB_KEY('RSA', @priv);-- Encrypt using private key, decrypt using public keySET @ciphertext = ASYMMETRIC_ENCRYPT('RSA', 'The quick brown fox', @priv);SET @cleartext = ASYMMETRIC_DECRYPT('RSA', @ciphertext, @pub);-- Encrypt using public key, decrypt using private keySET @ciphertext = ASYMMETRIC_ENCRYPT('RSA', 'The quick brown fox', @pub);SET @cleartext = ASYMMETRIC_DECRYPT('RSA', @ciphertext, @priv);
SET @s = a string to be encrypted SET @priv = a valid private RSA key string in PEM format SET @pub = the corresponding public RSA key string in PEM format
ASYMMETRIC_DECRYPT('RSA', ASYMMETRIC_ENCRYPT('RSA', @s, @priv), @pub) = @s ASYMMETRIC_DECRYPT('RSA', ASYMMETRIC_ENCRYPT('RSA', @s, @pub), @priv) = @s
ASYMMETRIC_SIGN(
algorithm
,
digest_str
,
priv_key_str
,
digest_type
)
NULL
digest_str
CREATE_DIGEST()
digest_type
priv_key_str
algorithm
algorithm
'DSA'
digest_type
'SHA256'
'SHA512'
ASYMMETRIC_VERIFY()
ASYMMETRIC_VERIFY(
algorithm
,
digest_str
,
sig_str
,
pub_key_str
,
digest_type
)
digest_str
CREATE_DIGEST()
digest_type
sig_str
ASYMMETRIC_SIGN()
pub_key_str
ASYMMETRIC_SIGN()
algorithm
algorithm
'DSA'
digest_type
'SHA256'
'SHA512'
-- Set the encryption algorithm and digest typeSET @algo = 'RSA';SET @dig_type = 'SHA224';-- Create private/public key pairSET @priv = CREATE_ASYMMETRIC_PRIV_KEY(@algo, 1024);SET @pub = CREATE_ASYMMETRIC_PUB_KEY(@algo, @priv);-- Generate digest from stringSET @dig = CREATE_DIGEST(@dig_type, 'The quick brown fox');-- Generate signature for digest and verify signature against digestSET @sig = ASYMMETRIC_SIGN(@algo, @dig, @priv, @dig_type);SET @verf = ASYMMETRIC_VERIFY(@algo, @dig, @sig, @pub, @dig_type);
CREATE_ASYMMETRIC_PRIV_KEY(
algorithm
,
{key_len
|dh_secret
})
NULL
algorithm
'DSA'
key_len
CREATE_DH_PARAMETERS()
SET @priv = CREATE_ASYMMETRIC_PRIV_KEY('DSA', 2048); SET @pub = CREATE_ASYMMETRIC_PUB_KEY('DSA', @priv);
ASYMMETRIC_DERIVE()
AES_ENCRYPT()
AES_DECRYPT()
CREATE_ASYMMETRIC_PUB_KEY(
algorithm
,
priv_key_str
)
NULL
priv_key_str
algorithm
algorithm
'DSA'
CREATE_ASYMMETRIC_PRIV_KEY()
CREATE_ASYMMETRIC_PRIV_KEY()
key_len
ASYMMETRIC_DERIVE()
SET @dhp = CREATE_DH_PARAMETERS(1024);
CREATE_DIGEST(
digest_type
,
str
)
NULL
digest_type
'SHA256'
'SHA512'
SET @dig = CREATE_DIGEST('SHA512', The quick brown fox');
ASYMMETRIC_SIGN()
AVG() | |
BIT_AND() | |
BIT_OR() | |
BIT_XOR() | |
COUNT() | |
COUNT(DISTINCT) | |
GROUP_CONCAT() | |
JSON_ARRAYAGG() | |
JSON_OBJECTAGG() | |
MAX() | |
MIN() | |
STD() | |
STDDEV() | |
STDDEV_POP() | |
STDDEV_SAMP() | |
SUM() | |
VAR_POP() | |
VAR_SAMP() | |
VARIANCE() |
NULL
GROUP BY
[
over_clause
]over_clause
DOUBLE
SUM()
AVG()
DECIMAL
DECIMAL
DOUBLE
FLOAT
DOUBLE
SUM()
AVG()
选择sec_to_time(sum(time_to_sec( time_col
从))) tbl_name
;选择from_days(和(to_days( date_col
从))) tbl_name
;
SUM()
AVG()
SET
ENUM
BIT_AND()
BIT_OR()
BIT_XOR()
BIGINT
BIGINT
BIGINT
BIGINT
BINARY
VARBINARY
BLOB
AVG([DISTINCT]
expr
)
[over_clause
]
expr
expr
AVG()
over_clause
over_clause
DISTINCT
MySQL的> SELECT student_name, AVG(test_score)
FROM student
GROUP BY student_name;
AND
expr
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
ER_INVALID_BITWISE_AGGREGATE_OPERANDS_SIZE
BIT_AND()
NULL
over_clause
over_clause
OR
expr
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
ER_INVALID_BITWISE_AGGREGATE_OPERANDS_SIZE
BIT_OR()
NULL
over_clause
over_clause
XOR
expr
NULL
ER_INVALID_BITWISE_OPERANDS_SIZE
ER_INVALID_BITWISE_AGGREGATE_OPERANDS_SIZE
BIT_XOR()
NULL
over_clause
over_clause
NULL
expr
SELECT
BIGINT
COUNT()
over_clause
over_clause
mysql>SELECT student.student_name,COUNT(*)
FROM student,course
WHERE student.student_id=course.student_id
GROUP BY student_name;
COUNT(*)
InnoDB
InnoDB
SELECT COUNT(*)
SELECT COUNT(*) FROM
tbl_name
WHERE
InnoDB
InnoDB
SELECT COUNT(*)
SHOW TABLE STATUS
InnoDB
SELECT COUNT(1)
MyISAM
COUNT(*)
SELECT
mysql> SELECT COUNT(*) FROM student;
MyISAM
NOT
NULL
COUNT(DISTINCT
expr
,[expr
...])
NULL
expr
COUNT(DISTINCT)
mysql> SELECT COUNT(DISTINCT results) FROM student;
NULL
COUNT(DISTINCT ...)
NULL
NULL
group_concat([明显] expr
【, expr
[…]以{ unsigned_integer
| col_name
| expr
asc desc | } [的], col_name
(分离器) str_val
])
MySQL的> SELECT student_name,
GROUP_CONCAT(test_score)
FROM student
GROUP BY student_name;
mysql>SELECT student_name,
GROUP_CONCAT(DISTINCT test_score
ORDER BY test_score DESC SEPARATOR ' ')
FROM student
GROUP BY student_name;
DISTINCT
DESC
ASC
SEPARATOR
group_concat_max_len
max_allowed_packet
group_concat_max_len
val
SET [GLOBAL | SESSION] group_concat_max_len =val
;
TEXT
BLOB
group_concat_max_len
VARCHAR
VARBINARY
JSON
mysql>SELECT o_id, attribute, value FROM t3;
+------+-----------+-------+ | o_id | attribute | value | +------+-----------+-------+ | 2 | color | red | | 2 | fabric | silk | | 3 | color | green | | 3 | shape | square| +------+-----------+-------+ 4 rows in set (0.00 sec) mysql>SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes
>FROM t3 GROUP BY o_id;
+------+---------------------+ | o_id | attributes | +------+---------------------+ | 2 | ["color", "fabric"] | | 3 | ["color", "shape"] | +------+---------------------+ 2 rows in set (0.00 sec)
NULL
mysql>SELECT o_id, attribute, value FROM t3;
+------+-----------+-------+ | o_id | attribute | value | +------+-----------+-------+ | 2 | color | red | | 2 | fabric | silk | | 3 | color | green | | 3 | shape | square| +------+-----------+-------+ 4 rows in set (0.00 sec) mysql>SELECT o_id, JSON_OBJECTAGG(attribute, value) FROM t3 GROUP BY o_id;
+------+----------------------------------------+ | o_id | JSON_OBJECTAGG(attribute, name) | +------+----------------------------------------+ | 2 | {"color": "red", "fabric": "silk"} | | 3 | {"color": "green", "shape": "square"} | +------+----------------------------------------+ 1 row in set (0.00 sec)
MAX([DISTINCT]
expr
)
[over_clause
]
expr
MAX()
DISTINCT
expr
MAX()
over_clause
over_clause
DISTINCT
MySQL的> SELECT student_name, MIN(test_score), MAX(test_score)
FROM student
GROUP BY student_name;
MIN([DISTINCT]
expr
)
[over_clause
]
expr
MIN()
DISTINCT
expr
MIN()
over_clause
over_clause
DISTINCT
MySQL的> SELECT student_name, MIN(test_score), MAX(test_score)
FROM student
GROUP BY student_name;
expr
STD()
STDDEV_POP()
STD()
over_clause
over_clause
expr
STDDEV()
STDDEV_POP()
STDDEV()
over_clause
over_clause
STDDEV_POP(
expr
)
[over_clause
]
expr
VAR_POP()
STD()
STDDEV()
STDDEV_POP()
over_clause
over_clause
STDDEV_SAMP(
expr
)
[over_clause
]
expr
VAR_SAMP()
STDDEV_SAMP()
over_clause
over_clause
SUM([DISTINCT]
expr
)
[over_clause
]
expr
SUM()
DISTINCT
expr
SUM()
over_clause
over_clause
DISTINCT
expr
VARIANCE()
VAR_POP()
over_clause
over_clause
expr
VAR_SAMP()
over_clause
over_clause
expr
VARIANCE()
VAR_POP()
VARIANCE()
over_clause
over_clause
GROUP BY
ROLLUP
sales
country
profit
Create Table Sales(Year Int,Country Varchar(20),Product Varchar(32),Profit Int);
GROUP BY
MySQL的> SELECT year, SUM(profit) AS profit
FROM sales
GROUP BY year;
------ -------- |年|利润| ------ -------- | 2000 | 4525 | | 2001 | 3010 | ------ --------
ROLLUP
GROUP
BY
MySQL的> SELECT year, SUM(profit) AS profit
FROM sales
GROUP BY year WITH ROLLUP;
------ -------- |年|利润| ------ -------- | 2000 | 4525 | | 2001 | 3010 | |空| 7535 | ------ --------
NULL
ROLLUP
ROLLUP
year
product
MySQL的> SELECT year, country, product, SUM(profit) AS profit
FROM sales
GROUP BY year, country, product;
------ --------- ------------ -------- |年|国|产品|利润| ------ --------- ------------ -------- | 2000 |芬兰|计算机| 1500 | | 2000 |芬兰|电话| 100 | | 2000 |印度|计算器| 150 | | 2000 |印度|计算机| 1200 | | 2000 |美国|计算器| 75 | | 2000 |美国|计算机| 1500 | | 2001 |芬兰|电话| 10 | | 2001 |美国|计算器| 50 | | 2001 |美国|计算机| 2700 | | 2001 |美国|电视| 250 | ------ --------- ------------ --------
ROLLUP
MySQL的> SELECT year, country, product, SUM(profit) AS profit
FROM sales
GROUP BY year, country, product WITH ROLLUP;
------ --------- ------------ -------- |年|国|产品|利润| ------ --------- ------------ -------- | 2000 |芬兰|计算机| 1500 | | 2000 |芬兰|电话| 100 | | 2000 |芬兰|空| 1600 | | 2000 |印度|计算器| 150 | | 2000 |印度|计算机| 1200 | | 2000 |印度|空| 1350 | | 2000 |美国|计算器| 75 | | 2000 |美国|计算机| 1500 | | 2000 |美国|空| 1575 | | 2000 |空|空| 4525 | | 2001 |芬兰|电话| 10 | | 2001 |芬兰|空| 10 | | 2001 |美国|计算器| 50 | | 2001 |美国|计算机| 2700 | | 2001 |美国|电视| 250 | | 2001 |美国|空| 3000 | | 2001 |空|空| 3010 | |空|空|空| 7535 | ------ --------- ------------ --------
product
country
NULL
year
products
DISTINCT
WITH ROLLUP
GROUP BY ... WITH ROLLUP
GROUPING()
ORDER BY
GROUPING(year)
year
GROUPING(country)
GROUPING(product)
country
mysql>SELECT
year, country, product, SUM(profit) AS profit,
GROUPING(year) AS grp_year,
GROUPING(country) AS grp_country,
GROUPING(product) AS grp_product
FROM sales
GROUP BY year, country, product WITH ROLLUP;
+------+---------+------------+--------+----------+-------------+-------------+ | year | country | product | profit | grp_year | grp_country | grp_product | +------+---------+------------+--------+----------+-------------+-------------+ | 2000 | Finland | Computer | 1500 | 0 | 0 | 0 | | 2000 | Finland | Phone | 100 | 0 | 0 | 0 | | 2000 | Finland | NULL | 1600 | 0 | 0 | 1 | | 2000 | India | Calculator | 150 | 0 | 0 | 0 | | 2000 | India | Computer | 1200 | 0 | 0 | 0 | | 2000 | India | NULL | 1350 | 0 | 0 | 1 | | 2000 | USA | Calculator | 75 | 0 | 0 | 0 | | 2000 | USA | Computer | 1500 | 0 | 0 | 0 | | 2000 | USA | NULL | 1575 | 0 | 0 | 1 | | 2000 | NULL | NULL | 4525 | 0 | 1 | 1 | | 2001 | Finland | Phone | 10 | 0 | 0 | 0 | | 2001 | Finland | NULL | 10 | 0 | 0 | 1 | | 2001 | USA | Calculator | 50 | 0 | 0 | 0 | | 2001 | USA | Computer | 2700 | 0 | 0 | 0 | | 2001 | USA | TV | 250 | 0 | 0 | 0 | | 2001 | USA | NULL | 3000 | 0 | 0 | 1 | | 2001 | NULL | NULL | 3010 | 0 | 1 | 1 | | NULL | NULL | NULL | 7535 | 1 | 1 | 1 | +------+---------+------------+--------+----------+-------------+-------------+
GROUPING()
GROUPING()
mysql>SELECT
IF(GROUPING(year), 'All years', year) AS year,
IF(GROUPING(country), 'All countries', country) AS country,
IF(GROUPING(product), 'All products', product) AS product,
SUM(profit) AS profit
FROM sales
GROUP BY year, country, product WITH ROLLUP;
+-----------+---------------+--------------+--------+ | year | country | product | profit | +-----------+---------------+--------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | Finland | All products | 1600 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | | 2000 | India | All products | 1350 | | 2000 | USA | Calculator | 75 | | 2000 | USA | Computer | 1500 | | 2000 | USA | All products | 1575 | | 2000 | All countries | All products | 4525 | | 2001 | Finland | Phone | 10 | | 2001 | Finland | All products | 10 | | 2001 | USA | Calculator | 50 | | 2001 | USA | Computer | 2700 | | 2001 | USA | TV | 250 | | 2001 | USA | All products | 3000 | | 2001 | All countries | All products | 3010 | | All years | All countries | All products | 7535 | +-----------+---------------+--------------+--------+
GROUPING()
GROUPING(year, country, product)
结果分组( product
分组的结果是() country
) << 1+ result for GROUPING(year
) << 2
GROUPING()
mysql>SELECT year, country, product, SUM(profit) AS profit
FROM sales
GROUP BY year, country, product WITH ROLLUP
HAVING GROUPING(year, country, product) <> 0;
+------+---------+---------+--------+ | year | country | product | profit | +------+---------+---------+--------+ | 2000 | Finland | NULL | 1600 | | 2000 | India | NULL | 1350 | | 2000 | USA | NULL | 1575 | | 2000 | NULL | NULL | 4525 | | 2001 | Finland | NULL | 10 | | 2001 | USA | NULL | 3000 | | 2001 | NULL | NULL | 3010 | | NULL | NULL | NULL | 7535 | +------+---------+---------+--------+
sales
NULL
NULL
NULL
GROUPING()
NULL
mysql> SELECT * FROM t1;
+------+-------+----------+
| name | size | quantity |
+------+-------+----------+
| ball | small | 10 |
| ball | large | 20 |
| ball | NULL | 5 |
| hoop | small | 15 |
| hoop | large | 5 |
| hoop | NULL | 3 |
+------+-------+----------+
ROLLUP
NULL
MySQL的> SELECT name, size, SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP;
------ ------- ---------- |名字|大小|数量| ------ ------- ---------- |球|空| 5 | |球|大| 20 | |球|小| 10 | |球|空| 35 | |箍|空| 3 | |箍|大| 5 | |箍|小| 15 | |箍|空| 23 | |空|空| 58 | ------ ------- ----------
GROUPING()
mysql>SELECT
IF(GROUPING(name) = 1, 'All items', name) AS name,
IF(GROUPING(size) = 1, 'All sizes', size) AS size,
SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP;
+-----------+-----------+----------+ | name | size | quantity | +-----------+-----------+----------+ | ball | NULL | 5 | | ball | large | 20 | | ball | small | 10 | | ball | All sizes | 35 | | hoop | NULL | 3 | | hoop | large | 5 | | hoop | small | 15 | | hoop | All sizes | 23 | | All items | All sizes | 58 | +-----------+-----------+----------+
ROLLUP
ROLLUP
ROLLUP
ROLLUP
ORDER
BY
MySQL的> SELECT * FROM
(SELECT year, SUM(profit) AS profit
FROM sales GROUP BY year WITH ROLLUP) AS dt
ORDER BY year DESC;
------ -------- |年|利润| ------ -------- | 2001 | 3010 | | 2000 | 4525 | |空| 7535 | ------ --------
ORDER BY
ORDER BY
GROUPING()
MySQL的> SELECT year, SUM(profit) AS profit
FROM sales
GROUP BY year WITH ROLLUP
ORDER BY GROUPING(year) DESC;
------ -------- |年|利润| ------ -------- |空| 7535 | | 2000 | 4525 | | 2001 | 3010 | ------ --------
LIMIT
ROLLUP
mysql>SELECT year, country, product, SUM(profit) AS profit
FROM sales
GROUP BY year, country, product WITH ROLLUP
LIMIT 5;
+------+---------+------------+--------+ | year | country | product | profit | +------+---------+------------+--------+ | 2000 | Finland | Computer | 1500 | | 2000 | Finland | Phone | 100 | | 2000 | Finland | NULL | 1600 | | 2000 | India | Calculator | 150 | | 2000 | India | Computer | 1200 | +------+---------+------------+--------+
LIMIT
NULL
NULL
NULL
HAVING
WHERE
NULL
NULL
GROUP BY
WITH ROLLUP
GROUP BY
MySQL的> SELECT year, country, SUM(profit) AS profit
FROM sales
GROUP BY year WITH ROLLUP;
------ --------- -------- |年|国|利润| ------ --------- -------- | 2000 |印度| 4525 | | 2001 |美国| 3010 | |空|美国| 7535 | ------ --------- --------
ONLY_FULL_GROUP_BY
GROUP BY
ONLY_FULL_GROUP_BY
mysql>SELECT year, ANY_VALUE(country) AS country, SUM(profit) AS profit
FROM sales
GROUP BY year WITH ROLLUP;
+------+---------+--------+ | year | country | profit | +------+---------+--------+ | 2000 | India | 4525 | | 2001 | USA | 3010 | | NULL | USA | 7535 | +------+---------+--------+
HAVING
GROUP BY
GROUP BY
SELECT o.custid, c.name, MAX(o.payment) FROM orders AS o, customers AS c WHERE o.custid = c.custid GROUP BY o.custid;
name
GROUP
BY
custid
customers
ONLY_FULL_GROUP_BY
ORDER BY
ONLY_FULL_GROUP_BY
HAVING
GROUP
BY
ORDER BY
ONLY_FULL_GROUP_BY
ONLY_FULL_GROUP_BY
ANY_VALUE()
ONLY_FULL_GROUP_BY
GROUP BY
选择的名称,地址,最大(年龄)T组的名字;
name
NOT
NULL
address
name
NOT
NULL
MySQL的> SELECT name, address, MAX(age) FROM t GROUP BY name;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUPBY clause and contains nonaggregated column 'mydb.t.address' whichis not functionally dependent on columns in GROUP BY clause; thisis incompatible with sql_mode=only_full_group_by
name
address
ANY_VALUE()
选择的名字,any_value(地址)、马克斯(年龄)T组的名字;
ONLY_FULL_GROUP_BY
GROUP
BY
ORDER BY
ONLY_FULL_GROUP_BY
MySQL的> SELECT name, MAX(age) FROM t;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression#1 of SELECT list contains nonaggregated column 'mydb.t.name'; thisis incompatible with sql_mode=only_full_group_by
GROUP BY
ANY_VALUE()
SELECT ANY_VALUE(name), MAX(age) FROM t;
ONLY_FULL_GROUP_BY
ORDER
BY
c1
c3
C1、C2 c31 A3 B1(C 2 2 4
c3
选择不同的C1,C2,C3 T;
c3
ORDER BY
HAVING
orders
SELECT name, COUNT(name) FROM orders GROUP BY name HAVING COUNT(name) = 1;
HAVING
SELECT name, COUNT(name) AS c FROM orders GROUP BY name HAVING c = 1;
GROUP
BY
SELECT id, FLOOR(value/100)
FROM tbl_name
GROUP BY id, FLOOR(value/100);
GROUP BY
GROUP
BY
选择ID、地板(价值/ 100)为Val从 tbl_name
集团通过ID,价值;
val
GROUP
BY
ONLY_FULL_GROUP_BY
FLOOR()
ONLY_FULL_GROUP_BY
FLOOR()
SELECT id, FLOOR(value/100), id+FLOOR(value/100)
FROM tbl_name
GROUP BY id, FLOOR(value/100);
SELECT id, F, id+F
FROM
(SELECT id, FLOOR(value/100) AS F
FROM tbl_name
GROUP BY id, FLOOR(value/100)) AS dt;
{X
} -> {Y
}
X
Y
Y
X
world
SELECT co.Name, COUNT(*) FROM countrylanguage cl, country co WHERE cl.CountryCode = co.Code GROUP BY co.Code;
co.Code
co
co.code { } { }>有限公司
co.name
UNIQUE
UNIQUE
NULL
SELECT co.Name, cl.Language, cl.Percentage * co.Population / 100.0 AS SpokenBy FROM countrylanguage cl, country co WHERE cl.CountryCode = co.Code GROUP BY cl.CountryCode, cl.Language;
cl.CountryCode
cl
{cl.CountryCode, cl.Language} -> {cl.*}
WHERE
cl.countrycode } { } { co.code >
co.Code
{co.Code} -> {co.*}
{cl.CountryCode, cl.Language} -> {cl.*,co.*}
UNIQUE
INNER JOIN
SELECT co.Name, cl.Language, cl.Percentage * co.Population/100.0 AS SpokenBy FROM countrylanguage cl INNER JOIN country co ON cl.CountryCode = co.Code GROUP BY cl.CountryCode, cl.Language;
WHERE
countrylanguage
LEFT JOIN
SELECT co.Name, cl.Language,cl.Percentage * co.Population/100.0 AS SpokenByFROM countrylanguage cl LEFT JOIN country coON cl.CountryCode = co.CodeGROUP BY cl.CountryCode, cl.Language;
cl.CountryCode
cl.CountryCode
cl.CountryCode
cl.countrycode } { } { co.code >
cl.CountryCode
cl.Language
co.Code
co.Name
NULL
co.Name
co.code } { } { co.name >
{cl.CountryCode, cl.Language} -> {cl.*,co.*}
SELECT co.Name, cl.Language, cl.Percentage * co.Population/100.0 AS SpokenBy FROM country co LEFT JOIN countrylanguage cl ON cl.CountryCode = co.Code GROUP BY cl.CountryCode, cl.Language;
{cl.CountryCode, cl.Language} -> {cl.*,co.*}
NULL
GROUP BY
co.Name
LEFT JOIN
CREATE VIEW Country2 AS SELECT co.Code, UPPER(co.Name) AS UpperName, COUNT(cl.Language) AS OfficialLanguages FROM country AS co JOIN countrylanguage AS cl ON cl.CountryCode = co.Code WHERE cl.isOfficial = 'T' GROUP BY co.Code;
{co.Code} -> {co.*}
co.Code
country2.code } { } { country2 >。
city
SELECT co2.Code, co2.UpperName, co2.OfficialLanguages,COUNT(*) AS CitiesFROM country2 AS co2 JOIN city ciON ci.CountryCode = co2.CodeGROUP BY co2.Code;
{co2.Code} -> {co2.*}
country2
SELECT co2.Code, co2.UpperName, co2.OfficialLanguages,COUNT(*) AS CitiesFROM( SELECT co.Code, UPPER(co.Name) AS UpperName, COUNT(cl.Language) AS OfficialLanguages FROM country AS co JOIN countrylanguage AS cl ON cl.CountryCode=co.Code WHERE cl.isOfficial='T' GROUP BY co.Code) AS co2JOIN city ci ON ci.CountryCode = co2.CodeGROUP BY co2.Code;
OVER
OVER
CUME_DIST() | |
DENSE_RANK() | |
FIRST_VALUE() | |
LAG() | |
LAST_VALUE() | |
LEAD() | |
NTH_VALUE() | |
NTILE() | |
PERCENT_RANK() | |
RANK() | |
ROW_NUMBER() |
over_clause
null_treatment
RESPECT NULLS
IGNORE NULLS
CUME_DIST()
over_clause
ORDER
BY
N
N
= 1, whereN
over_clause
val
PERCENT_RANK()
ROW_NUMBER()
MySQL的> SELECT
val,
ROW_NUMBER() OVER w AS 'row_number',
CUME_DIST() OVER w AS 'cume_dist',
PERCENT_RANK() OVER w AS 'percent_rank'
FROM numbers
WINDOW w AS (ORDER BY val);
------ ------------ -------------------- -------------- | Val | row_number | cume_dist | percent_rank | ------ ------------ -------------------- -------------- | 1 | 1 | 0.2222222222222222 | 0 | | 1 | 2 | 0.2222222222222222 | 0 | | 2 |三| 0.3333333333333333 | 0.25 | |三|四| 0.6666666666666666 | 375 | |三|五| 0.6666666666666666 | 375 | |三|六| 0.6666666666666666 | 375 | |四| 7 | 0.8888888888888888 | 0.75% | |四| 8 | 0.8888888888888888 | 0.75% | |五| 9 | 1 | 1 | ------ ------------ -------------------- --------------
DENSE_RANK()
over_clause
RANK()
ORDER
BY
over_clause
FIRST_VALUE(
expr
)null_treatment
over_clause
expr
over_clause
null_treatment
FIRST_VALUE()
LAST_VALUE()
NTH_VALUE()
MySQL的> SELECT
time, subject, val,
FIRST_VALUE(val) OVER w AS 'first',
LAST_VALUE(val) OVER w AS 'last',
NTH_VALUE(val, 2) OVER w AS 'second',
NTH_VALUE(val, 4) OVER w AS 'fourth'
FROM observations
WINDOW w AS (PARTITION BY subject ORDER BY time
ROWS UNBOUNDED PRECEDING);
---------- --------- ------ ------- ------ -------- -------- |时间|主体| Val |第一|最后|二|四| ---------- --------- ------ ------- ------ -------- -------- | 07:00:00 | st113 |十|十|十|空|空| | 07:15:00 | st113 | 9十9 | | | 9 |空| | 07:30:00 | st113 | 25 |十| 25 | 9 |空| | 07:45:00 | st113 | 20 |十| 20 | 9 | 20 | | 07:00:00 | xh458 | 0 0 0 | | |空|空| | 07:15:00 | xh458 |十| 0 |十|十|空| | 07:30:00 | xh458 | 5 0 | |五|十|空| | 07:45:00 | xh458 | 30 | 0 | 30 |十| 30 | | 08:00:00 | xh458 | 25 | 0 | 25 |十| 30 | ---------- --------- ------ ------- ------ -------- --------
NTH_VALUE()
LAG(
expr
[,
N
[,
default
]])null_treatment
over_clause
expr
N
default
N
default
N
default
N
N
expr
over_clause
null_treatment
LAG()
LEAD()
LAG()
LEAD()
MySQL的> SELECT
t, val,
LAG(val) OVER w AS 'lag',
LEAD(val) OVER w AS 'lead',
val - LAG(val) OVER w AS 'lag diff',
val - LEAD(val) OVER w AS 'lead diff'
FROM series
WINDOW w AS (ORDER BY t);
选择------ ------ ------选择------------- | T | Val |躺躺|铅铅| diff | diff | ------------------ ------ ------ ------选择------------- | 12:00 | 100 125 | | |零零| 25 | | 13:00 | 125 | 100 | 132 | 25 | 7 | | 14:00:00 | 132 | 145 125 | | 7 | 13 15 | | 00:00:00 | 132 140 145 | | | 13 | 5 | | 16:00 | | 145 140 150 | | | 5 10 | | 17:00 | | | 140 150 | | 200 10 18 50 | | 00:00:00 | 200 150 50 | | | |零零| ------------------ ------ ------ ------选择-------------
LAG()
LEAD()
N
default
LAG()
default
LEAD()
LAG()
LEAD()
MySQL的> SELECT n FROM fib ORDER BY n;
??????| N | | 1 | | | | 1 2 3 5 | | | | | | 8 |???
LAG()
LEAD()
MySQL的> SELECT
n,
LAG(n, 1, 0) OVER w AS 'lag',
LEAD(n, 1, 0) OVER w AS 'lead',
n + LAG(n, 1, 0) OVER w AS 'next_n',
n + LEAD(n, 1, 0) OVER w AS 'next_next_n'
FROM fib
WINDOW w AS (ORDER BY n);
------ ------ ------ -------- ------------- | N |滞后|铅| next_n | next_next_n | ------ ------ ------ -------- ------------- | 1 | 0 | 1 | 1 | 2 | | 1 | 1 | 2 | 2 | 3 | | 2 | 1 | 3 | 3 | 5 | | 3 | 2 | | | 5 5 8 | | 5 | 3 | 8 | 8 | 13 | | 8 | 5 | 0 | 13 | 8 | ------ ------ ------ -------- -------------
LAST_VALUE(
expr
)null_treatment
over_clause
expr
over_clause
null_treatment
FIRST_VALUE()
LEAD(
expr
[,
N
[,
default
]])null_treatment
over_clause
expr
N
default
N
default
N
default
N
N
expr
over_clause
null_treatment
LAG()
NTH_VALUE(
expr
,
N
)from_first_last
null_treatment
over_clause
expr
N
N
from_first_last
FROM LAST
ORDER BY
over_clause
null_treatment
FIRST_VALUE()
NTILE(
N
)over_clause
N
N
N
N
N
ORDER
BY
over_clause
val
ROW_NUMBER()
MySQL的> SELECT
val,
ROW_NUMBER() OVER w AS 'row_number',
NTILE(2) OVER w AS 'ntile2',
NTILE(4) OVER w AS 'ntile4'
FROM numbers
WINDOW w AS (ORDER BY val);
------ ------------ -------- -------- | Val | row_number | ntile2 | ntile4 | ------ ------------ -------- -------- | 1 | 1 | 1 | 1 | | 1 | 2 | 1 | 1 | | 2 | 3 | 1 | 1 | | 3 | 4 | 1 | 2 | | 3 | 5 | 1 | 2 | | 3 | 6 | 2 | 3 | | 4 | 7 | 2 | 3 | | 4 | 8 | 2 | 4 | | 5 | 9 | 2 | 4 | ------ ------------ -------- --------
PERCENT_RANK()
over_clause
rank
rows
( rank
- 1)/( rows
- 1)
ORDER
BY
over_clause
CUME_DIST()
RANK()
over_clause
ORDER
BY
over_clause
RANK()
DENSE_RANK()
RANK()
DENSE_RANK()
ROW_NUMBER()
MySQL的> SELECT
val,
ROW_NUMBER() OVER w AS 'row_number',
RANK() OVER w AS 'rank',
DENSE_RANK() OVER w AS 'dense_rank'
FROM numbers
WINDOW w AS (ORDER BY val);
------ ------------------ ------ ------------------ | Val |行_秩秩数| |密集_ | ------ ------------------ ------ ------------------ | | | 1 1 1 1 1 | | | | | 1 2 1 2 3 | | | | | | 2 3 3 4 4 | | | | | 3 3 4 5 | | | | | | | 3 6 3 3 4 | | | | | | 7 7 4 4 4 | | | | | | 7 8 4 5 9 | | | | | | 9 5 | ------ ------------------。------------------
ROW_NUMBER()
over_clause
ORDER BY
ROW_NUMBER()
RANK()
DENSE_RANK()
RANK()
over_clause
GROUPING()
mysql> SELECT * FROM sales ORDER BY country, year, product;
+------+---------+------------+--------+
| year | country | product | profit |
+------+---------+------------+--------+
| 2000 | Finland | Computer | 1500 |
| 2000 | Finland | Phone | 100 |
| 2001 | Finland | Phone | 10 |
| 2000 | India | Calculator | 75 |
| 2000 | India | Calculator | 75 |
| 2000 | India | Computer | 1200 |
| 2000 | USA | Calculator | 75 |
| 2000 | USA | Computer | 1500 |
| 2001 | USA | Calculator | 50 |
| 2001 | USA | Computer | 1500 |
| 2001 | USA | Computer | 1200 |
| 2001 | USA | TV | 150 |
| 2001 | USA | TV | 100 |
+------+---------+------------+--------+
mysql>SELECT SUM(profit) AS total_profit
FROM sales;
+--------------+ | total_profit | +--------------+ | 7535 | +--------------+ mysql>SELECT country, SUM(profit) AS country_profit
FROM sales
GROUP BY country
ORDER BY country;
+---------+----------------+ | country | country_profit | +---------+----------------+ | Finland | 1610 | | India | 1350 | | USA | 4575 | +---------+----------------+
SUM()
MySQL的> SELECT
year, country, product, profit,
SUM(profit) OVER() AS total_profit,
SUM(profit) OVER(PARTITION BY country) AS country_profit
FROM sales
ORDER BY country, year, product, profit;
------ --------- ------------ -------- -------------- ---------------- |年|国|产品|利润| total_profit | country_profit | ------ --------- ------------ -------- -------------- ---------------- | 2000 |芬兰|计算机| 1500 | 7535 | 1610年| | 2000 |芬兰|电话|百| 7535 | 1610年| | 2001年|芬兰|电话|十| 7535 | 1610年| | 2000 |印度|计算器| 75 | 7535 | 1350 | | 2000 |印度|计算器| 75 | 7535 | 1350 | | 2000 |印度|计算机| 1200 | 7535 | 1350 | | 2000 |美国|计算器| 75 | 7535 |四五七五| | 2000 |美国|计算机| 1500 | 7535 |四五七五| | 2001年|美国|计算器|五十| 7535 |四五七五| | 2001年|美国|计算机| 1200 | 7535 |四五七五| | 2001年|美国|计算机| 1500 | 7535 |四五七五| | 2001年美国||电视|百| 7535 |四五七五| | 2001年|美国|电视| 150 | 7535 |四五七五| ------ --------- ------------ -------- -------------- ----------------
OVER
OVER
OVER
ORDER BY
WHERE
HAVING
LIMIT
OVER
AVG() BIT_AND() BIT_OR() BIT_XOR() COUNT() MAX() MIN() STDDEV_POP(), STDDEV(), STD() STDDEV_SAMP() SUM() VAR_POP(), VARIANCE() VAR_SAMP()
OVER
cume_dist() dense_rank() first_value() lag() last_value() lead() nth_value() ntile() percent_rank() rank() row_number()
ROW_NUMBER()
row_num1
ORDER BY
MySQL的> SELECT
year, country, product, profit,
ROW_NUMBER() OVER(PARTITION BY country) AS row_num1,
ROW_NUMBER() OVER(PARTITION BY country ORDER BY year, product) AS row_num2
FROM sales;
------ --------- ------------ -------- ---------- ---------- |年|国|产品|利润| row_num1 | row_num2 | ------ --------- ------------ -------- ---------- ---------- | 2000 |芬兰|计算机| 1500 | 2 | 1 | | 2000 |芬兰|电话| 100 | 1 | 2 | | 2001 |芬兰|电话| 10 | 3 | 3 | | 2000 |印度|计算器| 75 | 2 | 1 | | 2000 |印度|计算器| 75 | 3 | 2 | | 2000 |印度|计算机| 1200 | 1 | 3 | | 2000 |美国|计算器| 75 | 5 | 1 | | 2000 |美国|计算机| | | 1500 4 2 | | 2001 |美国|计算器| 50 | 2 | 3 | | 2001 |美国|计算机| 1500 | 3 | 4 | | 2001 |美国|计算机| 1200 | 7 | 5 | | 2001 |美国|电视| 150 | 1 | 6 | | 2001 |美国|电视| 100 | 6 | 7 | ------ --------- ------------—------- ---------- ----------
OVER
over_clause
: {OVER (window_spec
) | OVERwindow_name
}
OVER
OVER
window_name
OVER
(
window_spec
)
window_spec
:[ window_name
] [ partition_clause
] [ order_clause
] [ frame_clause
]
OVER()
window_name
window_name
partition_clause
PARTITION BY
partition_clause
partition_clause
:分区 expr
【, expr
]…
PARTITION BY
TIMESTAMP
PARTITION BY ts
order_clause
ORDER BY
order_clause
order_clause
:订单 expr
[说明] [ | ASC, expr
| desc〔AUC〕…
ORDER BY
DESC
NULL
ORDER BY
frame_clause
N
level
MySQL的> SELECT
time, subject, val,
SUM(val) OVER (PARTITION BY subject ORDER BY time
ROWS UNBOUNDED PRECEDING)
AS running_total,
AVG(val) OVER (PARTITION BY subject ORDER BY time
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
AS running_average
FROM observations;
---------- --------- ------ --------------- ----------------- |时间|主体| Val | running_total | running_average | ---------- --------- ------ --------------- ----------------- | 07:00:00 | st113 | 10 | 10 | 9.5000 | | 07:15:00 | st113 | 9 | 19 | 14.6667 | | 07:30:00 | st113 | 25 | 44 | 18 | | 07:45:00 | st113 | | | 20 64 22.5000 | | 07:00:00 | xh458 | 0 | 0 | 5 | | 07:15:00 | xh458 | 10 | 10 | 5 | | 07:30:00 | xh458 | 5 | 15 | 15 | | 07:45:00 | xh458 | 30 | 45 | 20 | | 08:00:00 | xh458 | 25 | 70 | 27.5000 | ---------- --------- ------ --------------- -----------------
running_average
AVG()
FIRST_VALUE() LAST_VALUE() NTH_VALUE()
CUME_DIST() DENSE_RANK() LAG() LEAD() NTILE() PERCENT_RANK() RANK() ROW_NUMBER()
frame_clause
:frame_units
frame_extent
frame_units
: {ROWS | RANGE}
ORDER BY
frame_units
ROWS
RANGE
frame_extent
frame_extent
: {frame_start
|frame_between
}frame_between
: BETWEENframe_start
ANDframe_end
frame_start
,frame_end
: { CURRENT ROW | UNBOUNDED PRECEDING | UNBOUNDED FOLLOWING |expr
PRECEDING |expr
FOLLOWING }
BETWEEN
frame_start
frame_end
frame_start
frame_end
CURRENT ROW
RANGE
UNBOUNDED PRECEDING
UNBOUNDED FOLLOWING
expr
PRECEDINGexpr
expr
expr
PRECEDINGexpr
expr
INTERVAL
val
unit
val
unit
units
DATE_ADD()
RANGE
expr
expr
PRECEDINGexpr
10 precedinginterval 5天preceding5 followinginterval的2:30的minute_second以下
expr
FOLLOWINGexpr
expr
expr
expr
FIRST_VALUE()
LAST_VALUE()
NTH_VALUE()
MySQL的> SELECT
time, subject, val,
FIRST_VALUE(val) OVER w AS 'first',
LAST_VALUE(val) OVER w AS 'last',
NTH_VALUE(val, 2) OVER w AS 'second',
NTH_VALUE(val, 4) OVER w AS 'fourth'
FROM observations
WINDOW w AS (PARTITION BY subject ORDER BY time
ROWS UNBOUNDED PRECEDING);
---------- --------- ------ ------- ------ -------- -------- |时间|主体| Val |第一|最后|二|四| ---------- --------- ------ ------- ------ -------- -------- | 07:00:00 | st113 |十|十|十|空|空| | 07:15:00 | st113 | 9十9 | | | 9 |空| | 07:30:00 | st113 | 25 |十| 25 | 9 |空| | 07:45:00 | st113 | 20 |十| 20 | 9 | 20 | | 07:00:00 | xh458 | 0 0 0 | | |空|空| | 07:15:00 | xh458 |十| 0 |十|十|空| | 07:30:00 | xh458 | 5 0 | |五|十|空| | 07:45:00 | xh458 | 30 | 0 | 30 |十| 30 | | 08:00:00 | xh458 | 25 | 0 | 25 |十| 30 | ---------- --------- ------ ------- ------ -------- --------
NTH_VALUE()
ORDER BY
ORDER BY
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
ORDER BY
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
ORDER BY
SUM()
ORDER BY
NULL
ORDER BY X ASC RANGE BETWEEN 10 FOLLOWING AND 15
FOLLOWING
NULL
NULL
ORDER BY X ASC RANGE BETWEEN 10 FOLLOWING AND
UNBOUNDED FOLLOWING
NULL
NULL
ORDER BY X DESC RANGE BETWEEN 10 FOLLOWING AND
UNBOUNDED FOLLOWING
NULL
NULL
ORDER BY X ASC RANGE BETWEEN 10 PRECEDING AND
UNBOUNDED FOLLOWING
NULL
NULL
ORDER BY X ASC RANGE BETWEEN 10 PRECEDING AND 10
FOLLOWING
NULL
NULL
ORDER BY X ASC RANGE BETWEEN 10 PRECEDING AND 1
PRECEDING
NULL
NULL
ORDER BY X ASC RANGE BETWEEN UNBOUNDED PRECEDING
AND 10 FOLLOWING
NULL
NULL
OVER
WINDOW
ORDER BY
窗口 window_name
为( window_spec
)[, window_name
为( window_spec
)]…
window_name
window_spec
window_spec
: [window_name
] [partition_clause
] [order_clause
] [frame_clause
]
WINDOW
OVER
选择在瓦尔,row_number()(顺序由Val)为“row_number ',rank()超过(以val)为“等级”,在dense_rank()(顺序由Val)为“dense_rank'from数;
WINDOW
SELECT val, ROW_NUMBER() OVER w AS 'row_number', RANK() OVER w AS 'rank', DENSE_RANK() OVER w AS 'dense_rank' FROM numbers WINDOW w AS (ORDER BY val);
WINDOW
OVER
window_name
window_name
OVER
选择不同的一年,国家,first_value(年)在(W为年ASC)为先,first_value(年)在(W为年DESC)作为从saleswindow W(分国家);
OVER
OVER
在(W为国家)…窗口w(分国家)
OVER
PARTITION BY
在(W分区年)…窗口w(分国家)
window_name
WINDOW w1 AS (w2), w2 AS (), w3 AS (w1)
WINDOW w1 AS (w2), w2 AS (w3), w3 AS (w1)
CAN_ACCESS_COLUMN() | |
CAN_ACCESS_DATABASE() | |
CAN_ACCESS_TABLE() | |
CAN_ACCESS_VIEW() | |
GET_DD_COLUMN_PRIVILEGES() | |
GET_DD_CREATE_OPTIONS() | |
GET_DD_INDEX_SUB_PART_LENGTH() | |
INTERNAL_AUTO_INCREMENT() | |
INTERNAL_AVG_ROW_LENGTH() | |
INTERNAL_CHECK_TIME() | |
INTERNAL_CHECKSUM() | |
INTERNAL_DATA_FREE() | |
INTERNAL_DATA_LENGTH() | |
INTERNAL_DD_CHAR_LENGTH() | |
INTERNAL_GET_COMMENT_OR_ERROR() | |
INTERNAL_GET_VIEW_WARNING_OR_ERROR() | |
INTERNAL_INDEX_COLUMN_CARDINALITY() | |
INTERNAL_INDEX_LENGTH() | |
INTERNAL_KEYS_DISABLED() | |
INTERNAL_MAX_DATA_LENGTH() | |
INTERNAL_TABLE_ROWS() | |
INTERNAL_UPDATE_TIME() |
ANY_VALUE() | |
BIN_TO_UUID() | |
DEFAULT() | |
GET_LOCK() | |
GROUPING() | |
INET_ATON() | |
INET_NTOA() | |
INET6_ATON() | |
INET6_NTOA() | |
IS_FREE_LOCK() | |
IS_IPV4() | |
IS_IPV4_COMPAT() | |
IS_IPV4_MAPPED() | |
IS_IPV6() | |
IS_USED_LOCK() | |
IS_UUID() | |
MASTER_POS_WAIT() | |
NAME_CONST() | |
RAND() | |
RELEASE_ALL_LOCKS() | |
RELEASE_LOCK() | |
SLEEP() | |
UUID() | |
UUID_SHORT() | |
UUID_TO_BIN() | |
VALUES() |
GROUP BY
ONLY_FULL_GROUP_BY
ONLY_FULL_GROUP_BY
name
ONLY_FULL_GROUP_BY
MySQL的> SELECT name, address, MAX(age) FROM t GROUP BY name;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUPBY clause and contains nonaggregated column 'mydb.t.address' whichis not functionally dependent on columns in GROUP BY clause; thisis incompatible with sql_mode=only_full_group_by
address
address
name
address
address
NULL
ANY_VALUE()
SELECT name, ANY_VALUE(address), MAX(age) FROM t GROUP BY name;
address
ANY_VALUE()
SUM()
COUNT()
ONLY_FULL_GROUP_BY
ANY_VALUE()
ONLY_FULL_GROUP_BY
ANY_VALUE()
age-1
ONLY_FULL_GROUP_BY
选择年龄从岁年龄组;
ANY_VALUE()
选择any_value(年龄)T组的年龄;
ANY_VALUE()
mysql> SELECT name, MAX(age) FROM t;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression
#1 of SELECT list contains nonaggregated column 'mydb.t.name'; this
is incompatible with sql_mode=only_full_group_by
GROUP BY
ANY_VALUE()
选择any_value(的名字),马克斯(年龄)T;
GROUP BY
ANY_VALUE()
BIN_TO_UUID(
binary_uuid
)BIN_TO_UUID(
binary_uuid
,
swap_flag
)
BIN_TO_UUID()
UUID_TO_BIN()
VARBINARY(16)
UUID()
NULL
BIN_TO_UUID()
swap_flag
swap_flag
UUID_TO_BIN()
DEFAULT(
col_name
)
MySQL的> UPDATE t SET i = DEFAULT(i)+1 WHERE id < 100;
X
D
str
timeout
timeout
1
NULL
GET_LOCK()
RELEASE_LOCK()
GET_LOCK()
GET_LOCK()
GET_LOCK()
GET_LOCK()
metadata_locks
USER
LEVEL LOCK
ER_USER_LOCK_DEADLOCK
SELECT GET_LOCK('lock1',10); SELECT GET_LOCK('lock2',10); SELECT RELEASE_LOCK('lock2'); SELECT RELEASE_LOCK('lock1');
GET_LOCK()
RELEASE_LOCK()
GET_LOCK()
GET_LOCK()
GET_LOCK()
db_name.str
app_name.str
GET_LOCK()
binlog_format
INSERT INTO ... SELECT GET_LOCK(t1.col_name) FROM t1;
GET_LOCK()
GROUP BY
ROLLUP
GROUPING()
NULL
GROUPING()
GROUPING()
GROUPING()
GROUPING()
NULL
t1
mysql> SELECT * FROM t1;
+------+-------+----------+
| name | size | quantity |
+------+-------+----------+
| ball | small | 10 |
| ball | large | 20 |
| ball | NULL | 5 |
| hoop | small | 15 |
| hoop | large | 5 |
| hoop | NULL | 3 |
+------+-------+----------+
WITH ROLLUP
MySQL的> SELECT name, size, SUM(quantity) AS quantity
FROM t1
GROUP BY name, size;
------ ------- ---------- |名字|大小|数量| ------ ------- ---------- |球|小|十| |球|大| 20 | |球|空|五| |箍|小| 15 | |箍|大|五| |箍|空|三| ------ ------- ----------
NULL
WITH ROLLUP
NULL
MySQL的> SELECT name, size, SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP;
------ ------- ---------- |名字|大小|数量| ------ ------- ---------- |球|空| 5 | |球|大| 20 | |球|小| 10 | |球|空| 35 | |箍|空| 3 | |箍|大| 5 | |箍|小| 15 | |箍|空| 23 | |空|空| 58 | ------ ------- ----------
NULL
GROUPING()
mysql>SELECT
name, size, SUM(quantity) AS quantity,
GROUPING(name) AS grp_name,
GROUPING(size) AS grp_size
FROM t1
GROUP BY name, size WITH ROLLUP;
+------+-------+----------+----------+----------+ | name | size | quantity | grp_name | grp_size | +------+-------+----------+----------+----------+ | ball | NULL | 5 | 0 | 0 | | ball | large | 20 | 0 | 0 | | ball | small | 10 | 0 | 0 | | ball | NULL | 35 | 0 | 1 | | hoop | NULL | 3 | 0 | 0 | | hoop | large | 5 | 0 | 0 | | hoop | small | 15 | 0 | 0 | | hoop | NULL | 23 | 0 | 1 | | NULL | NULL | 58 | 1 | 1 | +------+-------+----------+----------+----------+
GROUPING()
NULL
MySQL的> SELECT
IF(GROUPING(name) = 1, 'All items', name) AS name,
IF(GROUPING(size) = 1, 'All sizes', size) AS size,
SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP;
----------- ----------- ---------- |名字|大小|数量| ----------- ----------- ---------- |球|空| 5 | |球|大| 20 | |球|小| 10 | |球|大小| 35 | |箍|空| 3 | |箍|大| 5 | |箍|小| 15 | |箍|大小| 23 | |所有项目|大小| 58 | ----------- ----------- ----------
mysql>SELECT name, size, SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP
HAVING GROUPING(name) = 1 OR GROUPING(size) = 1;
+------+------+----------+ | name | size | quantity | +------+------+----------+ | ball | NULL | 35 | | hoop | NULL | 23 | | NULL | NULL | 58 | +------+------+----------+
GROUPING()
GROUPING()
GROUPING(
expr1
,
expr2
,
expr3
)
结果分组( expr3
分组的结果是() expr2
) << 1+ result for GROUPING(expr1
) << 2
GROUPING()
MySQL的> SELECT
name, size, SUM(quantity) AS quantity,
GROUPING(name) AS grp_name,
GROUPING(size) AS grp_size,
GROUPING(name, size) AS grp_all
FROM t1
GROUP BY name, size WITH ROLLUP;
------ ------- ---------- ---------- ---------- --------- |名字|大小|数量| grp_name | grp_size | grp_all | ------ ------- ---------- ---------- ---------- --------- |球|空| 5 | 0 | 0 | 0 | |球|大| 20 | 0 | 0 | 0 | |球|小| 10 0 0 0 | | | | |球|空| 35 | 0 | 1 | 1 | |箍|空| 3 | 0 | 0 | 0 | |箍|大| 5 | 0 | 0 | 0 | |箍|小| 15 | 0 | 0 | 0 | |箍|空| | | | 1 1 0 23 | |空|空| 58 | 1 | 1 | 3 | ------ ------- ---------- ---------- ---------- ---------
GROUPING()
GROUPING()
GROUPING()
MySQL的> SELECT name, size, SUM(quantity) AS quantity
FROM t1
GROUP BY name, size WITH ROLLUP
HAVING GROUPING(name, size) <> 0;
------ ------ ---------- |名字|大小|数量| ------ ------ ---------- |球|空| 35 | |箍|空| 23 | |空|空| 58 | ------ ------ ----------
GROUPING()
GROUP BY
GROUPING()
MySQL的> SELECT GROUPING((SELECT MAX(name) FROM t1))
FROM t1
GROUP BY (SELECT MAX(name) FROM t1) WITH ROLLUP;
错误3580(hy000):论证# 1分组功能不在组
GROUP BY
GROUPING()
HAVING
GROUPING()
SELECT a AS f1, 'w' AS f2FROM tGROUP BY f1, f2 WITH ROLLUPHAVING GROUPING(f2) = 1;
GROUPING()
EXPLAIN
Extra
WITH ROLLUP
GROUPING()
INET_ATON()
mysql> SELECT INET_ATON('10.0.5.9');
-> 167773449
INET_ATON()
'127.1'
INET_ATON()
INET_ATON()
INT
INET_NTOA()
mysql> SELECT INET_NTOA(167773449);
-> '10.0.5.9'
VARBINARY
VARBINARY(16)
VARBINARY(4)
INET6_ATON()
HEX()
INET6_ATON()
MySQL的> SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089'));
-> 'FDFE0000000000005A55CAFFFEFA9089'mysql>SELECT HEX(INET6_ATON('10.0.5.9'));
这是0a000509→
INET6_ATON()
fe80::3%1
2001:45f:3:ba::/64
198.51.1
198.0xa0.1.2
198.51.10.1
expr
INT
VARBINARY
inet6 _阿顿(_ ntoa(核能与新能源技术研究院 expr
))
mysql> SELECT HEX(INET6_ATON(INET_NTOA(167773449)));
-> '0A000509'
INET6_NTOA()
INET6_NTOA()
CREATE TABLE t AS SELECT INET6_NTOA(expr
) AS c1;
CREATE TABLE t (c1 VARCHAR(39) CHARACTER SET utf8 DEFAULT NULL);
mysql>SELECT INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089'));
-> 'fdfe::5a55:caff:fefa:9089' mysql>SELECT INET6_NTOA(INET6_ATON('10.0.5.9'));
-> '10.0.5.9' mysql>SELECT INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089'));
-> 'fdfe::5a55:caff:fefa:9089' mysql>SELECT INET6_NTOA(UNHEX('0A000509'));
-> '10.0.5.9'
str
0
binlog_format
mysql> SELECT IS_IPV4('10.0.5.9'), IS_IPV4('10.0.5.256');
-> 1, 0
IS_IPV4()
INET_ATON()
INET6_ATON()
INET_ATON()
IS_IPV4()
IS_IPV4()
INET_ATON()
INET6_ATON()
INET6_ATON()
IS_IPV4()
INET6_ATON()
ipv4_address
MySQL的> SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'));
-> 1mysql>SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9'));
> 0
198.51.100.1
MySQL的> SELECT HEX(INET6_ATON('198.51.100.1'));
c6336401”- >“
::198.51.100.1
::c0a8:1
MySQL的> SELECT
-> IS_IPV4_COMPAT(INET6_ATON('::198.51.100.1')),
-> IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')),
-> IS_IPV4_COMPAT(INET6_ATON('::c0a8:1'));
> 1,1,1
INET6_ATON()
ipv4_address
MySQL的> SELECT IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9'));
-> 0mysql>SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:10.0.5.9'));
-> 1
IS_IPV4_COMPAT()
MySQL的> SELECT
-> IS_IPV4_MAPPED(INET6_ATON('::ffff:198.51.100.1')),
-> IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:0001')),
-> IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:1'));
> 1,1,1
mysql> SELECT IS_IPV6('10.0.5.9'), IS_IPV6('::1');
-> 0, 1
IS_IPV6()
INET6_ATON()
str
binlog_format
NULL
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
aaaaaaaabbbbccccddddeeeeeeeeeeee {aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee}
UUID()
MySQL的> SELECT IS_UUID('6ccd780c-baba-1026-9564-5b8c656024db');
------------------------------------------------- | is_uuid('6ccd780c-baba-1026-9564-5b8c656024db”)| ------------------------------------------------- | 1 | ------------------------------------------------- MySQL > SELECT IS_UUID('6CCD780C-BABA-1026-9564-5B8C656024DB');
------------------------------------------------- | is_uuid('6ccd780c-baba-1026-9564-5b8c656024db”)| ------------------------------------------------- | 1 | ------------------------------------------------- MySQL > SELECT IS_UUID('6ccd780cbaba102695645b8c656024db');
--------------------------------------------- | is_uuid('6ccd780cbaba102695645b8c656024db”)| --------------------------------------------- | 1 | --------------------------------------------- MySQL > SELECT IS_UUID('{6ccd780c-baba-1026-9564-5b8c656024db}');
--------------------------------------------------- | is_uuid(“{ }”6ccd780c-baba-1026-9564-5b8c656024db)| --------------------------------------------------- | 1 | --------------------------------------------------- MySQL > SELECT IS_UUID('6ccd780c-baba-1026-9564-5b8c6560');
--------------------------------------------- | is_uuid('6ccd780c-baba-1026-9564-5b8c6560”)| --------------------------------------------- | 0 | --------------------------------------------- MySQL > SELECT IS_UUID(RAND());
| ----------------------是_(UUID)的边缘(0)| --------------------- | | ---------------------
MASTER_POS_WAIT(
log_name
,log_pos
[,timeout
][,channel
])
NULL
MASTER_POS_WAIT()
slave_checkpoint_group
slave_checkpoint_period
timeout
MASTER_POS_WAIT()
timeout
timeout
timeout
channel
binlog_format
NAME_CONST()
MySQL的> SELECT NAME_CONST('myname', 14);
“……………………”
mysql> SELECT 14 AS myname;
+--------+
| myname |
+--------+
| 14 |
+--------+
1 row in set (0.00 sec)
binlog_format
str
GET_LOCK()
0
GET_LOCK()
DO
RELEASE_LOCK()
binlog_format
duration
SLEEP()
mysql> SELECT SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
| 0 |
+-------------+
SLEEP()
KILL QUERY
MySQL的> SELECT SLEEP(1000);
------------- |睡眠(1000)| ------------- | 1 | -------------
mysql> SELECT /*+ MAX_EXECUTION_TIME(1) */ SLEEP(1000);
+-------------+
| SLEEP(1000) |
+-------------+
| 1 |
+-------------+
SLEEP()
KILL QUERY
MySQL的> SELECT 1 FROM t1 WHERE SLEEP(1000);
错误1317(70100):查询执行被中断
mysql> SELECT /*+ MAX_EXECUTION_TIME(1000) */ 1 FROM t1 WHERE SLEEP(1000);
ERROR 3024 (HY000): Query execution was interrupted, maximum statement
execution time exceeded
binlog_format
UUID()
UUID()
UUID()
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
mysql> SELECT UUID();
-> '6ccd780c-baba-1026-9564-5b8c656024db'
UUID_TO_BIN()
BIN_TO_UUID()
IS_UUID()
UUID()
UUID_SHORT()
UUID()
UUID_SHORT()
server_id
UUID_SHORT()
UUID_SHORT()
(server_id & 255) << 56+ (server_startup_time_in_seconds << 24)+ incremented_variable++;
mysql> SELECT UUID_SHORT();
-> 92395783831158784
UUID_SHORT()
UUID_TO_BIN(
string_uuid
)UUID_TO_BIN(
string_uuid
,
swap_flag
)
IS_UUID()
VARBINARY(16)
NULL
UUID_TO_BIN()
swap_flag
swap_flag
UUID()
UUID()
mysql> SET @uuid = '6ccd780c-baba-1026-9564-5b8c656024db';
UUID_TO_BIN()
MySQL的> SELECT HEX(UUID_TO_BIN(@uuid));
---------------------------------- |十六进制(UUID _(@ UUID)是一_)| ---------------------------------- | 6ccd780cbaba102695645b8c656024db | ---------------------------------- MySQL > SELECT HEX(UUID_TO_BIN(@uuid, 0));
---------------------------------- |十六进制(UUID _ to _宾(@ UUID,0)| ---------------------------------- | 6ccd780cbaba102695645b8c656024db | ---------------------------------- MySQL > SELECT HEX(UUID_TO_BIN(@uuid, 1));
---------------------------------- |十六进制(UUID _对_仓(@ UUID,1))| ---------------------------------- | 1026baba6ccd780c95645b8c656024db | ----------------------------------
UUID_TO_BIN()
BIN_TO_UUID()
UUID_TO_BIN()
BIN_TO_UUID()
MySQL的> SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid));
-------------------------------------- | bin_to_uuid(uuid_to_bin(@ UUID))| -------------------------------------- | 6ccd780c-baba-1026-9564-5b8c656024db | -------------------------------------- MySQL > SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid,0),0);
-------------------------------------- | bin_to_uuid(uuid_to_bin(@ UUID,0),0)| -------------------------------------- | 6ccd780c-baba-1026-9564-5b8c656024db | -------------------------------------- MySQL > SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid,1),1);
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
mysql>SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid,0),1);
+--------------------------------------+ | BIN_TO_UUID(UUID_TO_BIN(@uuid,0),1) | +--------------------------------------+ | baba1026-780c-6ccd-9564-5b8c656024db | +--------------------------------------+ mysql>SELECT BIN_TO_UUID(UUID_TO_BIN(@uuid,1),0);
+--------------------------------------+ | BIN_TO_UUID(UUID_TO_BIN(@uuid,1),0) | +--------------------------------------+ | 1026baba-6ccd-780c-9564-5b8c656024db | +--------------------------------------+
INSERT
... ON DUPLICATE KEY UPDATE
col_name
UPDATE
INSERT
col_name
UPDATE
col_name
VALUES()
INSERT
mysql>INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
->ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
.0001
ROUND()
NULL
DECIMAL
1
3.4
-6.78
1.2E3
-1.2E3
2.34
DECIMAL
DECIMAL
NUMERIC
DEC
FIXED
FLOAT
DOUBLE
FLOAT
DOUBLE
DOUBLE PRECISION
REAL
DECIMAL
DECIMAL
DECIMAL
M
D
M
D
M
M
DECIMAL
DECIMAL
DECIMAL(18,9)
DECIMAL
-
+0003.1
3.1
DECIMAL
-999
DECIMAL(
M
,D
)M
D
NUMERIC(
M
,D
)M
M
D
M
M
D
M
D
M
DECIMAL
decimal2bin()
INSERT
DECIMAL
INSERT
sql_mode
STRICT_ALL_TABLES
STRICT_TRANS_TABLES
ERROR_FOR_DIVISION_BY_ZERO
TRADITIONAL
ERROR_FOR_DIVISION_BY_ZERO
MySQL的> SET sql_mode='TRADITIONAL';
DECIMAL
NULL
ERROR_FOR_DIVISION_BY_ZERO
ERROR_FOR_DIVISION_BY_ZERO
INSERT INTO t SET i = 1/0;
ERROR_FOR_DIVISION_BY_ZERO
sql_mode | |
---|---|
'' | i
|
i
| |
ERROR_FOR_DIVISION_BY_ZERO | i
|
ERROR_FOR_DIVISION_BY_ZERO |
ROUND()
DECIMAL
ROUND()
mysql> SELECT ROUND(2.5), ROUND(25E-1);
+------------+--------------+
| ROUND(2.5) | ROUND(25E-1) |
+------------+--------------+
| 3 | 2 |
+------------+--------------+
DECIMAL
mysql>CREATE TABLE t (d DECIMAL(10,0));
Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO t VALUES(2.5),(2.5E0);
Query OK, 2 rows affected, 2 warnings (0.00 sec) Records: 2 Duplicates: 0 Warnings: 2 mysql>SELECT d FROM t;
+------+ | d | +------+ | 3 | | 3 | +------+
mysql> SELECT (.1 + .2) = .3;
+----------------+
| (.1 + .2) = .3 |
+----------------+
| 1 |
+----------------+
mysql> SELECT (.1E0 + .2E0) = .3E0;
+----------------------+
| (.1E0 + .2E0) = .3E0 |
+----------------------+
| 0 |
+----------------------+
.0001
CREATE PROCEDURE p ()BEGIN DECLARE i INT DEFAULT 0; DECLARE d DECIMAL(10,4) DEFAULT 0; DECLARE f FLOAT DEFAULT 0; WHILE i < 10000 DO SET d = d + .0001; SET f = f + .0001E0; SET i = i + 1; END WHILE; SELECT d, f;END;
d
+--------+------------------+ | d | f | +--------+------------------+ | 1.0000 | 0.99999999999991 | +--------+------------------+
X1
X2
S1
S2
S1
S2
MySQL的> SELECT .01 * .01;
----------- |。01。01 | ----------- | 0.0001 | -----------
ROUND()
DECIMAL
mysql> SELECT ROUND(2.5), ROUND(-2.5);
+------------+-------------+
| ROUND(2.5) | ROUND(-2.5) |
+------------+-------------+
| 3 | -3 |
+------------+-------------+
mysql> SELECT ROUND(2.5E0), ROUND(-2.5E0);
+--------------+---------------+
| ROUND(2.5E0) | ROUND(-2.5E0) |
+--------------+---------------+
| 2 | -2 |
+--------------+---------------+
mysql>SET sql_mode='';
Query OK, 0 rows affected (0.00 sec) mysql>CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.01 sec) mysql>INSERT INTO t SET i = 128;
Query OK, 1 row affected, 1 warning (0.00 sec) mysql>SELECT i FROM t;
+------+ | i | +------+ | 127 | +------+ 1 row in set (0.00 sec)
mysql>SET sql_mode='STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.00 sec) mysql>CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO t SET i = 128;
ERROR 1264 (22003): Out of range value adjusted for column 'i' at row 1 mysql>SELECT i FROM t;
Empty set (0.00 sec)
ERROR_FOR_DIVISION_BY_ZERO
NULL
MySQL的> SET sql_mode='';
查询好,为受影响的行(0.01秒)MySQL > CREATE TABLE t (i TINYINT);
查询好,为受影响的行(0.001秒)MySQL > INSERT INTO t SET i = 1 / 0;
查询行,1行的影响(0秒)MySQL > SELECT i FROM t;
------ |我| ------ |空| ------ 1行集(0.03秒)
mysql>SET sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
Query OK, 0 rows affected (0.00 sec) mysql>CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO t SET i = 1 / 0;
ERROR 1365 (22012): Division by 0 mysql>SELECT i FROM t;
Empty set (0.01 sec)
DECIMAL
MySQL的> CREATE TABLE t SELECT 2.5 AS a, 25E-1 AS b;
查询行,1行的影响(0.01秒)记录:1份:0警告:0mysql > DESCRIBE t;
------- ----------------------- ------ ----- --------- ------- |场|型|空|关键|默认|额外| ------- ----------------------- ------ ----- --------- ------- |一|十进制(2,1)符号|没有| | 0 | | | B |双|没有| | 0 | | ------- ----------------------- ------ ----- --------- ------- 2行集(0.01秒)
mysql>CREATE TABLE t (i INT, d DECIMAL, f FLOAT);
mysql>INSERT INTO t VALUES(1,1,1);
mysql>CREATE TABLE y SELECT AVG(i), AVG(d), AVG(f) FROM t;
mysql> DESCRIBE y;
+--------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------+------+-----+---------+-------+
| AVG(i) | decimal(14,4) | YES | | NULL | |
| AVG(d) | decimal(14,4) | YES | | NULL | |
| AVG(f) | double | YES | | NULL | |
+--------+---------------+------+-----+---------+-------+