Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when sync to mysql, data may not consitent with timestamp data type if explicit_defaults_for_timestamp var diffreent #284

Open
july2993 opened this issue May 31, 2018 · 0 comments

Comments

@july2993
Copy link
Contributor

in tidb will like this explicit_defaults_for_timestamp is on as default

mysql> create table tm(id int auto_increment, t_timestamp TIMESTAMP, primary key(id));
Query OK, 0 rows affected (0.24 sec)

mysql> show create table tm;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                        |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tm    | CREATE TABLE `tm` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `t_timestamp` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)

mysql> insert into tm(t_timestamp) values(null);
Query OK, 1 row affected (0.13 sec)

mysql> select * from tm;
+----+-------------+
| id | t_timestamp |
+----+-------------+
|  1 | NULL        |
+----+-------------+
1 row in set (0.01 sec)

in mysql if explicit_defaults_for_timestamp is off will like this
for mysql Default Value is ON(>= 8.0.2) or OFF(<= 8.0.1)

mysql> create table tm(id int auto_increment, t_timestamp TIMESTAMP, primary key(id));
Query OK, 0 rows affected (0.03 sec)

mysql> show create table tm;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                    |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tm    | CREATE TABLE `tm` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `t_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> insert into tm(t_timestamp) values(null);
Query OK, 1 row affected (0.00 sec)

mysql> select * from tm;
+----+---------------------+
| id | t_timestamp         |
+----+---------------------+
|  1 | 2018-05-31 12:55:51 |
+----+---------------------+
1 row in set (0.01 sec)

about explicit_defaults_for_timestamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant