diff --git a/dev/reference/mysql-compatibility.md b/dev/reference/mysql-compatibility.md index 5f9ca84bf712d..8914252ef19f8 100644 --- a/dev/reference/mysql-compatibility.md +++ b/dev/reference/mysql-compatibility.md @@ -10,7 +10,7 @@ TiDB supports both the MySQL wire protocol and the majority of its syntax. This Currently TiDB Server advertises itself as MySQL 5.7 and works with most MySQL database tools such as PHPMyAdmin, Navicat, MySQL Workbench, mysqldump, and mydumper/myloader. -However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, `Engine` in the `CREATE TABLE` statement can be parsed but is ignored. +However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, the `ENGINE` table option in the `CREATE TABLE` statement can be parsed but is ignored. > **Note:** > @@ -116,11 +116,23 @@ Views in TiDB are currently non-insertable and non-updatable. For compatibility reasons, TiDB supports the syntax to create tables with alternative storage engines. Metadata commands describe tables as being of engine InnoDB: +{{< copyable "sql" >}} + ```sql -mysql> CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +``` + +``` Query OK, 0 rows affected (0.14 sec) +``` -mysql> SHOW CREATE TABLE t1\G +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` + +``` *************************** 1. row *************************** Table: t1 Create Table: CREATE TABLE `t1` ( @@ -179,6 +191,11 @@ It is recommended to use the historical reads feature of `tidb_snapshot` to prod - Default value of `foreign_key_checks`: - The default value in TiDB is `OFF` and currently TiDB only supports `OFF`. - The default value in MySQL 5.7 is `ON`. +- Default SQL mode: + - The default SQL mode in TiDB includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION`. + - The default SQL mode in MySQL: + - The default SQL mode in MySQL 5.7 is the same as TiDB. + - The default SQL mode in MySQL 8.0 includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`. - Default value of `lower_case_table_names`: - The default value in TiDB is 2 and currently TiDB only supports 2. - The default value in MySQL: diff --git a/v2.1/reference/mysql-compatibility.md b/v2.1/reference/mysql-compatibility.md index 122c5ca5e87ce..fc539f6c22f60 100644 --- a/v2.1/reference/mysql-compatibility.md +++ b/v2.1/reference/mysql-compatibility.md @@ -10,6 +10,8 @@ TiDB supports both the MySQL wire protocol and the majority of its syntax. This Currently TiDB Server advertises itself as MySQL 5.7 and works with most MySQL database tools such as PHPMyAdmin, Navicat, MySQL Workbench, mysqldump, and Mydumper/myloader. +However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, the `ENGINE` table option and the `PARTITION BY` clause in the `CREATE TABLE` statement can be parsed but are ignored. + > **Note:** > > This page refers to general differences between MySQL and TiDB. Please also see the dedicated pages for [Security](/v2.1/reference/security/compatibility.md) and [Transaction Model](/v2.1/reference/transactions/transaction-model.md) compatibility. @@ -54,6 +56,8 @@ In TiDB, auto-increment columns are only guaranteed to be incremental and unique Assume that you have a table with the auto-increment ID: +{{< copyable "sql" >}} + ```sql create table t(id int unique key AUTO_INCREMENT, c int); ``` @@ -111,11 +115,23 @@ For more information, see [Online Schema Changes](/v2.1/key-features.md#online-s For compatibility reasons, TiDB supports the syntax to create tables with alternative storage engines. Metadata commands describe tables as being of engine InnoDB: +{{< copyable "sql" >}} + ```sql -mysql> CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +``` + +``` Query OK, 0 rows affected (0.14 sec) +``` + +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` -mysql> SHOW CREATE TABLE t1\G +``` *************************** 1. row *************************** Table: t1 Create Table: CREATE TABLE `t1` ( @@ -159,12 +175,17 @@ tidb> SELECT /*!90000 "I should not run", */ "I should run" FROM dual; ### Default differences - Default character set: - - The default value in TiDB is `utf8` which is equivalent to `utf8mb4` in MySQL. + - The default value in TiDB is `utf8mb4`. - The default value in MySQL 5.7 is `latin1`, but changes to `utf8mb4` in MySQL 8.0. -- Default collation: `latin1_swedish_ci` in MySQL 5.7, while `binary` in TiDB. +- Default collation: + - The default collation of `utf8mb4` in TiDB is `utf8mb4_bin`. + - The default collation of `utf8mb4` in MySQL 5.7 is `utf8mb4_general_ci`, but changes to `utf8mb4_0900_ai_ci` in MySQL 8.0. + - You can use the [`SHOW CHARACTER SET`](/v2.1/reference/sql/statements/show-character-set.md) statement to check the default collations of all character sets. - Default SQL mode: - - The default value in TiDB is `STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION`. - - The default value in MySQL 5.7 is `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION`. + - The default SQL mode in TiDB includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION`. + - The default SQL mode in MySQL: + - The default SQL mode in MySQL 5.7 is the same as TiDB. + - The default SQL mode in MySQL 8.0 includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`. - Default value of `lower_case_table_names`: - The default value in TiDB is 2 and currently TiDB only supports 2. - The default value in MySQL: diff --git a/v3.0/reference/mysql-compatibility.md b/v3.0/reference/mysql-compatibility.md index 528788f630085..930d1139bd534 100644 --- a/v3.0/reference/mysql-compatibility.md +++ b/v3.0/reference/mysql-compatibility.md @@ -10,7 +10,7 @@ TiDB supports both the MySQL wire protocol and the majority of its syntax. This Currently TiDB Server advertises itself as MySQL 5.7 and works with most MySQL database tools such as PHPMyAdmin, Navicat, MySQL Workbench, mysqldump, and Mydumper/myloader. -However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, `Engine` in the `CREATE TABLE` statement can be parsed but is ignored. +However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, the `ENGINE` table option in the `CREATE TABLE` statement can be parsed but is ignored. > **Note:** > @@ -54,6 +54,8 @@ In TiDB, auto-increment columns are only guaranteed to be incremental and unique Assume that you have a table with the auto-increment ID: +{{< copyable "sql" >}} + ```sql create table t(id int unique key AUTO_INCREMENT, c int); ``` @@ -116,11 +118,23 @@ Views in TiDB are currently non-insertable and non-updatable. For compatibility reasons, TiDB supports the syntax to create tables with alternative storage engines. Metadata commands describe tables as being of engine InnoDB: +{{< copyable "sql" >}} + ```sql -mysql> CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +``` + +``` Query OK, 0 rows affected (0.14 sec) +``` -mysql> SHOW CREATE TABLE t1\G +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` + +``` *************************** 1. row *************************** Table: t1 Create Table: CREATE TABLE `t1` ( @@ -173,6 +187,11 @@ tidb> SELECT /*!90000 "I should not run", */ "I should run" FROM dual; - Default value of `foreign_key_checks`: - The default value in TiDB is `OFF` and currently TiDB only supports `OFF`. - The default value in MySQL 5.7 is `ON`. +- Default SQL mode: + - The default SQL mode in TiDB includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION`. + - The default SQL mode in MySQL: + - The default SQL mode in MySQL 5.7 is the same as TiDB. + - The default SQL mode in MySQL 8.0 includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`. - Default value of `lower_case_table_names`: - The default value in TiDB is 2 and currently TiDB only supports 2. - The default value in MySQL: diff --git a/v3.1/reference/mysql-compatibility.md b/v3.1/reference/mysql-compatibility.md index 9e55042d059c8..0ce03de0b1924 100644 --- a/v3.1/reference/mysql-compatibility.md +++ b/v3.1/reference/mysql-compatibility.md @@ -10,7 +10,7 @@ TiDB supports both the MySQL wire protocol and the majority of its syntax. This Currently TiDB Server advertises itself as MySQL 5.7 and works with most MySQL database tools such as PHPMyAdmin, Navicat, MySQL Workbench, mysqldump, and Mydumper/myloader. -However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, `Engine` in the `CREATE TABLE` statement can be parsed but is ignored. +However, TiDB does not support some of MySQL features or behaves differently from MySQL because these features cannot be easily implemented in a distributed system. For some MySQL syntax, TiDB can parse but does not process it. For example, the `ENGINE` table option in the `CREATE TABLE` statement can be parsed but is ignored. > **Note:** > @@ -54,6 +54,8 @@ In TiDB, auto-increment columns are only guaranteed to be incremental and unique Assume that you have a table with the auto-increment ID: +{{< copyable "sql" >}} + ```sql create table t(id int unique key AUTO_INCREMENT, c int); ``` @@ -116,11 +118,23 @@ Views in TiDB are currently non-insertable and non-updatable. For compatibility reasons, TiDB supports the syntax to create tables with alternative storage engines. Metadata commands describe tables as being of engine InnoDB: +{{< copyable "sql" >}} + ```sql -mysql> CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +``` + +``` Query OK, 0 rows affected (0.14 sec) +``` -mysql> SHOW CREATE TABLE t1\G +{{< copyable "sql" >}} + +```sql +SHOW CREATE TABLE t1; +``` + +``` *************************** 1. row *************************** Table: t1 Create Table: CREATE TABLE `t1` ( @@ -173,6 +187,11 @@ tidb> SELECT /*!90000 "I should not run", */ "I should run" FROM dual; - Default value of `foreign_key_checks`: - The default value in TiDB is `OFF` and currently TiDB only supports `OFF`. - The default value in MySQL 5.7 is `ON`. +- Default SQL mode: + - The default SQL mode in TiDB includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION`. + - The default SQL mode in MySQL: + - The default SQL mode in MySQL 5.7 is the same as TiDB. + - The default SQL mode in MySQL 8.0 includes these modes: `ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`. - Default value of `lower_case_table_names`: - The default value in TiDB is 2 and currently TiDB only supports 2. - The default value in MySQL: