关于数据库:腾讯云TDSQL-MySQL版-开发指南兼容性

42次阅读

共计 12704 个字符,预计需要花费 32 分钟才能阅读完成。

语言构造
分布式实例反对所有 MySQL 应用的文字格局,包含:

String Literals
Numeric Literals
Date and Time Literals
Hexadecimal Literals
Bit-Value Literals
Boolean Literals
NULL Values
String Literals
String Literals 是一个 bytes 或者 characters 的序列,两端被单引号 ’ 或者双引号 ” 突围,TDSQL MySQL 版 目前不反对 ANSI_QUOTES SQL MODE,双引号 ” 突围的始终认为是 String Literals,而不是 identifier。

不反对 character set introducer,即 [_charset_name]’string’ [COLLATE collation_name] 这种格局。

反对的转义字符:

\0: ASCII NUL (X’00’) 字符
\‘: 单引号
\“: 双引号
\b: 退格符号
\n: 换行符
\r: 回车符
\t: tab 符(制表符)
\z: ASCII 26 (Ctrl + Z)
\: 反斜杠 \
\%: \%
\_: _
Numeric Literals
数值字面值包含 integer、Decimal 类型、浮点数字面值。
integer 能够包含. 作为小数点分隔,数字前能够有 - 或者 + 来示意负数或者正数。
准确数值字面值能够示意为如下格局:1, .2, 3.4, -5, -6.78, +9.10。
迷信记数法,如下格局:1.2E3, 1.2E-3, -1.2E3, -1.2E-3。

Date and Time Literals
DATE 反对如下格局:

‘YYYY-MM-DD’ or ‘YY-MM-DD’
‘YYYYMMDD’ or ‘YYMMDD’
YYYYMMDD or YYMMDD
如:’2012-12-31′, ‘2012/12/31’, ‘2012^12^31’, ‘2012@12@31’ ‘20070523’ , ‘070523’
DATETIME,TIMESTAMP 反对如下格局:

‘YYYY-MM-DD HH:MM:SS’ or ‘YY-MM-DD HH:MM:SS’
‘YYYYMMDDHHMMSS’ or ‘YYMMDDHHMMSS’
YYYYMMDDHHMMSS or YYMMDDHHMMSS
如 ’2012-12-31 11:30:45′, ‘2012^12^31 11+30+45’, ‘2012/12/31 113045′, ‘2012@12@31 11^30^45’,19830905132800
Hexadecimal Literals
反对格局如下:

X’01AF’
X’01af’
x’01AF’
x’01af’
0x01AF
0x01af
Bit-Value Literals
反对格局如下:

b’01’
B’01’
0b01
Boolean Literals
常量 TRUE 和 FALSE 等于 1 和 0,大小写不敏感。

mysql> SELECT TRUE, true, FALSE, false;
TRUETRUEFALSEFALSE
1100

1 row in set (0.03 sec)
NULL Values
NULL 代表数据为空,大小写不敏感,与 \N(大小写敏感)同义。
须要留神的是 NULL 跟 0 并不一样,跟空字符串 ” 也不一样。

字符集和时区
反对 MySQL 的所有字符集和字符序:

mysql> show character set;
CharsetDescriptionDefault collationMaxlen
big5Big5 Traditional Chinesebig5_chinese_ci2
dec8DEC West Europeandec8_swedish_ci1
cp850DOS West Europeancp850_general_ci1
hp8HP West Europeanhp8_english_ci1
koi8rKOI8-R Relcom Russiankoi8r_general_ci1
latin1cp1252 West Europeanlatin1_swedish_ci1
latin2ISO 8859-2 Central Europeanlatin2_general_ci1
swe77bit Swedishswe7_swedish_ci1
asciiUS ASCIIascii_general_ci1
ujisEUC-JP Japaneseujis_japanese_ci3
sjisShift-JIS Japanesesjis_japanese_ci2
hebrewISO 8859-8 Hebrewhebrew_general_ci1
tis620TIS620 Thaitis620_thai_ci1
euckrEUC-KR Koreaneuckr_korean_ci2
koi8uKOI8-U Ukrainiankoi8u_general_ci1
gb2312GB2312 Simplified Chinesegb2312_chinese_ci2
greekISO 8859-7 Greekgreek_general_ci1
cp1250Windows Central Europeancp1250_general_ci1
gbkGBK Simplified Chinesegbk_chinese_ci2
latin5ISO 8859-9 Turkishlatin5_turkish_ci1
armscii8ARMSCII-8 Armenianarmscii8_general_ci1
utf8UTF-8 Unicodeutf8_general_ci3
ucs2UCS-2 Unicodeucs2_general_ci2
cp866DOS Russiancp866_general_ci1
keybcs2DOS Kamenicky Czech-Slovakkeybcs2_general_ci1
macceMac Central Europeanmacce_general_ci1
macromanMac West Europeanmacroman_general_ci1
cp852DOS Central Europeancp852_general_ci1
latin7ISO 8859-13 Balticlatin7_general_ci1
utf8mb4UTF-8 Unicodeutf8mb4_general_ci4
cp1251Windows Cyrilliccp1251_general_ci1
utf16UTF-16 Unicodeutf16_general_ci4
utf16leUTF-16LE Unicodeutf16le_general_ci4
cp1256Windows Arabiccp1256_general_ci1
cp1257Windows Balticcp1257_general_ci1
utf32UTF-32 Unicodeutf32_general_ci4
binaryBinary pseudo charsetbinary1
geostd8GEOSTD8 Georgiangeostd8_general_ci1
cp932SJIS for Windows Japanesecp932_japanese_ci2
eucjpmsUJIS for Windows Japaneseeucjpms_japanese_ci3
gb18030China National Standard GB18030gb18030_chinese_ci4

41 rows in set (0.02 sec)
查看以后连贯的字符集:

mysql> show variables like “%char%”;
Variable_nameValue
character_set_clientlatin1
character_set_connectionlatin1
character_set_databaseutf8
character_set_filesystembinary
character_set_resultslatin1
character_set_serverutf8
character_set_systemutf8
character_sets_dir/data/tdsql_run/8812/percona-5.7.17/share/charsets/

设置以后连贯相干的字符集:

mysql> set names utf8;
Query OK, 0 rows affected (0.03 sec)

mysql> show variables like “%char%”;
Variable_nameValue
character_set_clientutf8
character_set_connectionutf8
character_set_databaseutf8
character_set_filesystembinary
character_set_resultsutf8
character_set_serverutf8
character_set_systemutf8
character_sets_dir/data/tdsql_run/8811/percona-5.7.17/share/charsets/

阐明:
分布式实例不反对设置全局参数,须要调用前台接口设置。

反对通过设置 time_zone 变量批改时区相干的属性:

mysql> show variables like ‘%time_zone%’;
Variable_nameValue
system_time_zoneCST
time_zoneSYSTEM

2 rows in set (0.00 sec)
mysql> create table test.tt (ts timestamp, dt datetime,c int) shardkey=c;
Query OK, 0 rows affected (0.49 sec)
mysql> insert into test.tt (ts,dt,c)values (‘2017-10-01 12:12:12’, ‘2017-10-01 12:12:12’,1);
Query OK, 1 row affected (0.09 sec)

mysql> select * from test.tt;
tsdtc
2017-10-01 12:12:122017-10-01 12:12:121

1 row in set (0.04 sec)
mysql> set time_zone = ‘+12:00’;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like ‘%time_zone%’;
Variable_nameValue
system_time_zoneCST
time_zone+12:00

2 rows in set (0.00 sec)

mysql> select * from test.tt;
tsdtc
2017-10-01 16:12:122017-10-01 12:12:121

1 row in set (0.06 sec)
数据类型
反对 MySQL 的所有数据类型,包含数字,字符,日期,空间类型,JSON。

数字
整型反对 INTEGER,INT,SMALLINT,TINYINT,MEDIUMINT,BIGINT

类型 字节数 最小值(有符号 / 无符号)最大值(有符号 / 无符号)
TINYINT 1 -128/0 127/255
SMALLINT 2 -32768/0 32767/65535
MEDIUMINT 3 -8388608/0 8388607/16777215
INT 4 -2147483648/0 2147483647/4294967295
BIGINT 8 -9223372036854775808/0 9223372036854775807/18446744073709551615
浮点类型反对 FLOAT 和 DOUBLE,格局 FLOAT(M,D)、REAL(M,D) 或 DOUBLE PRECISION(M,D)

定点类型反对 DECIMAL 和 NUMERIC,格局 DECIMAL(M,D)

字符
反对如下字符类型:

CHAR 和 VARCHAR Types
BINARY 和 VARBINARY Types
BLOB 和 TEXT Types
TINYBLOB,TINYTEXT,MEDIUMBLOB,MEDIUMTEXT,LONGBLOB,LONGTEXT
ENUM Type
SET Type
日期
反对如下工夫类型:

DATE, DATETIME, TIMESTAMP Types
TIME Type
YEAR Type
空间
反对如下空间类型:

GEOMETRY
POINT
LINESTRING
POLYGON
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
GEOMETRYCOLLECTION
JSON
反对存储 JSON 格局的数据,使得对 JSON 解决更加无效,同时又能提前查看谬误:

留神:
对 JSON 类型的字段进行排序时,不反对混合类型排序。如不能将 string 类型和 int 类型做比拟,同类型排序只反对数值类型,string 类型,其它类型排序不解决。对下表来说,不反对 select * from t1 order by t1->”$.key2″,因为排序列中蕴含了数值和字符串类型。

mysql> CREATE TABLE t1 (jdoc JSON,a int) shardkey=a;
Query OK, 0 rows affected (0.30 sec)
mysql> INSERT INTO t1 (jdoc,a)VALUES(‘{“key1”: “value1”, “key2”: “value2”}’,1);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 (jdoc,a)VALUES(‘{“key1”: “value1”, “key2”: 2}’,2);
mysql> INSERT INTO t1 (jdoc,a)VALUES(‘[1, 2,’,5);
ERROR 3140 (22032): Invalid JSON text: “Invalid value.” at position 6 in value for column ‘t1.jdoc’.

mysql> select * from t1;
jdoca
{“key1”: “value1”, “key2”: “value2”}1
{“key1”: “value1”, “key2”: 2}2

2 rows in set (0.00 sec)
函数反对
Control Flow Functions

Name Description
CASE Case operator
IF() If/else construct
IFNULL() Null if/else construct
NULLIF() Return NULL if expr1 = expr2
String Functions

Name Description
ASCII() Return numeric value of left-most character
BIN() Return a string containing binary representation of a number
BIT_LENGTH() Return length of argument in bits
CHAR() Return the character for each integer passed
CHAR_LENGTH() Return number of characters in argument
CHARACTER_LENGTH() Synonym for CHAR_LENGTH()
CONCAT() Return concatenated string
CONCAT_WS() Return concatenate with separator
ELT() Return string at index number
EXPORT_SET() Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
FIELD() Return the index (position) of the first argument in the subsequent arguments
FIND_IN_SET() Return the index position of the first argument within the second argument
FORMAT() Return a number formatted to specified number of decimal places
FROM_BASE64() Decode to a base-64 string and return result
HEX() Return a hexadecimal representation of a decimal or string value
INSERT() Insert a substring at the specified position up to the specified number of characters
INSTR() Return the index of the first occurrence of substring
LCASE() Synonym for LOWER()
LEFT() Return the leftmost number of characters as specified
LENGTH() Return the length of a string in bytes
LIKE Simple pattern matching
LOAD_FILE() Load the named file
LOCATE() Return the position of the first occurrence of substring
LOWER() Return the argument in lowercase
LPAD() Return the string argument, left-padded with the specified string
LTRIM() Remove leading spaces
MAKE_SET() Return a set of comma-separated strings that have the corresponding bit in bits set
MATCH Perform full-text search
MID() Return a substring starting from the specified position
NOT LIKE Negation of simple pattern matching
NOT REGEXP Negation of REGEXP
OCT() Return a string containing octal representation of a number
OCTET_LENGTH() Synonym for LENGTH()
ORD() Return character code for leftmost character of the argument
POSITION() Synonym for LOCATE()
QUOTE() Escape the argument for use in an SQL statement
REGEXP Pattern matching using regular expressions
REPEAT() Repeat a string the specified number of times
REPLACE() Replace occurrences of a specified string
REVERSE() Reverse the characters in a string
RIGHT() Return the specified rightmost number of characters
RLIKE Synonym for REGEXP
RPAD() Append string the specified number of times
RTRIM() Remove trailing spaces
SOUNDEX() Return a soundex string
SOUNDS LIKE Compare sounds
SPACE() Return a string of the specified number of spaces
STRCMP() Compare two strings
SUBSTR() Return the substring as specified
SUBSTRING() Return the substring as specified
SUBSTRING_INDEX() Return a substring from a string before the specified number of occurrences of the delimiter
TO_BASE64() Return the argument converted to a base-64 string
TRIM() Remove leading and trailing spaces
UCASE() Synonym for UPPER()
UNHEX() Return a string containing hex representation of a number
UPPER() Convert to uppercase
WEIGHT_STRING() Return the weight string for a string
Numeric Functions and Operators

Name Description
ABS() Return the absolute value
ACOS() Return the arc cosine
ASIN() Return the arc sine
ATAN() Return the arc tangent
ATAN2(), ATAN() Return the arc tangent of the two arguments
CEIL() Return the smallest integer value not less than the argument
CEILING() Return the smallest integer value not less than the argument
CONV() Convert numbers between different number bases
COS() Return the cosine
COT() Return the cotangent
CRC32() Compute a cyclic redundancy check value
DEGREES() Convert radians to degrees
DIV Integer division
/ Division operator
EXP() Raise to the power of
FLOOR() Return the largest integer value not greater than the argument
LN() Return the natural logarithm of the argument
LOG() Return the natural logarithm of the first argument
LOG10() Return the base-10 logarithm of the argument
LOG2() Return the base-2 logarithm of the argument

  • Minus operator
    MOD() Return the remainder
    %, MOD Modulo operator
    PI() Return the value of pi
  • Addition operator
    POW() Return the argument raised to the specified power
    POWER() Return the argument raised to the specified power
    RADIANS() Return argument converted to radians
    RAND() Return a random floating-point value
    ROUND() Round the argument
    SIGN() Return the sign of the argument
    SIN() Return the sine of the argument
    SQRT() Return the square root of the argument
    TAN() Return the tangent of the argument
  • Multiplication operator
    TRUNCATE() Truncate to specified number of decimal places
  • Change the sign of the argument
    Date and Time Functions

Name Description
ADDDATE() Add time values (intervals) to a date value
ADDTIME() Add time
CONVERT_TZ() Convert from one time zone to another
CURDATE() Return the current date
CURRENT_DATE(), CURRENT_DATE Synonyms for CURDATE()
CURRENT_TIME(), CURRENT_TIME Synonyms for CURTIME()
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP Synonyms for NOW()
CURTIME() Return the current time
DATE() Extract the date part of a date or datetime expression
DATE_ADD() Add time values (intervals) to a date value
DATE_FORMAT() Format date as specified
DATE_SUB() Subtract a time value (interval) from a date
DATEDIFF() Subtract two dates
DAY() Synonym for DAYOFMONTH()
DAYNAME() Return the name of the weekday
DAYOFMONTH() Return the day of the month (0-31)
DAYOFWEEK() Return the weekday index of the argument
DAYOFYEAR() Return the day of the year (1-366)
EXTRACT() Extract part of a date
FROM_DAYS() Convert a day number to a date
FROM_UNIXTIME() Format Unix timestamp as a date
GET_FORMAT() Return a date format string
HOUR() Extract the hour
LAST_DAY Return the last day of the month for the argument
LOCALTIME(), LOCALTIME Synonym for NOW()
LOCALTIMESTAMP, LOCALTIMESTAMP() Synonym for NOW()
MAKEDATE() Create a date from the year and day of year
MAKETIME() Create time from hour, minute, second
MICROSECOND() Return the microseconds from argument
MINUTE() Return the minute from the argument
MONTH() Return the month from the date passed
MONTHNAME() Return the name of the month
NOW() Return the current date and time
PERIOD_ADD() Add a period to a year-month
PERIOD_DIFF() Return the number of months between periods
QUARTER() Return the quarter from a date argument
SEC_TO_TIME() Converts seconds to ‘HH:MM:SS’ format
SECOND() Return the second (0-59)
STR_TO_DATE() Convert a string to a date
SUBDATE() Synonym for DATE_SUB() when invoked with three arguments
SUBTIME() Subtract times
SYSDATE() Return the time at which the function executes
TIME() Extract the time portion of the expression passed
TIME_FORMAT() Format as time
TIME_TO_SEC() Return the argument converted to seconds
TIMEDIFF() Subtract time
TIMESTAMP() With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments
TIMESTAMPADD() Add an interval to a datetime expression
TIMESTAMPDIFF() Subtract an interval from a datetime expression
TO_DAYS() Return the date argument converted to days
TO_SECONDS() Return the date or datetime argument converted to seconds since Year 0
UNIX_TIMESTAMP() Return a Unix timestamp
UTC_DATE() Return the current UTC date
UTC_TIME() Return the current UTC time
UTC_TIMESTAMP() Return the current UTC date and time
WEEK() Return the week number
WEEKDAY() Return the weekday index
WEEKOFYEAR() Return the calendar week of the date (1-53)
YEAR() Return the year
YEARWEEK() Return the year and week
Aggregate (GROUP BY) Functions

Name Description
AVG() Return the average value of the argument
COUNT() Return a count of the number of rows returned
MAX() Return the maximum value
MIN() Return the minimum value
SUM() Return the sum
Bit Functions and Operators

Name Description
BIT_COUNT() Return the number of bits that are set
& Bitwise AND
~ Bitwise inversion
| Bitwise OR
^ Bitwise XOR
<< Left shift

Right shift
Cast Functions and Operators

Name Description
BINARY Cast a string to a binary string
CAST() Cast a value as a certain type
CONVERT() Cast a value as a certain type

正文完
 0