Mysql8.0.22 设置默认值 DATE_FORMAT(sysdate() ,'%Y%m%d') 错误

Mysql8.0.22 set default value DATE_FORMAT(sysdate() ,'%Y%m%d') error

请原谅我糟糕的英语 这是我的 sql

create table if not exists `test` (
    `client_id` varchar(18) not null default ' ',
    `begin_date` int not null default DATE_FORMAT(sysdate() ,'%Y%m%d') ,
    `end_date` int not null default DATE_FORMAT(sysdate() ,'%Y%m%d'),
unique index `uk_key` (`client_id` asc)
) engine = InnoDB  default charset = utf8 collate = utf8_bin comment = '';
commit;  

10.3.18-MariaDB-log中执行后没有报错 但是在Mysql 8.0.22中,错误

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATE_FORMAT(sysdate() ,'%Y%m%d'),
    `end_date` int not nu' at line 

被举报;

我已经修改了@global.sql_mode和@sql_mode,但是没有用。

+-----------------------------------------------------------------------+
| @@sql_mode                                                            |
+-----------------------------------------------------------------------+
| STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
mysql> select @@global.sql_mode;
+-----------------------------------------------------------------------+
| @@global.sql_mode                                                     |
+-----------------------------------------------------------------------+
| STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------+

我该怎么办

阅读https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html

特别是:

The default value specified in a DEFAULT clause can be a literal constant or an expression. With one exception, enclose expression default values within parentheses to distinguish them from literal constant default values.

所以在 MySQL 中,与 MariaDB 不同的是,在将表达式用作默认值时,需要将表达式放在括号内。

示例:

create table if not exists `test` (
    `client_id` varchar(18) not null default ' ',
    `begin_date` int not null default (DATE_FORMAT(sysdate() ,'%Y%m%d')),
    `end_date` int not null default (DATE_FORMAT(sysdate() ,'%Y%m%d')),
unique index `uk_key` (`client_id` asc)
) engine = InnoDB  default charset = utf8 collate = utf8_bin comment = '';