check the manual that corresponds to your MySQL server version for the right syntax to use near
环境:MacOS,MySQL5.7
今天导出本地数据库「MySQL5.7」到其他库「MySQL5.5」一直报错,记录一下,具体如下:
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 '(6) DEFAULT NULL,
`del_flag` int(11) DEFAULT NULL,
`update_by` varchar(255) ' at line 4, Time: 0.009000s
我们可以看到是 MySQL 版本问题,由于不能直接升级 MySQL5.5 到 5.7 版本「某些原因」,所以只能改动一下SQL,我们看一下建表语句:
CREATE TABLE `app_exception` (
`id` varchar(255) NOT NULL,
`create_by` varchar(255) DEFAULT NULL,
`create_time` datetime(6) DEFAULT NULL,
`del_flag` int(11) DEFAULT NULL,
`update_by` varchar(255) DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`app_version` varchar(255) DEFAULT NULL,
`exception_msg` varchar(255) DEFAULT NULL,
`phone_model` varchar(255) DEFAULT NULL,
`phone_sys_version` varchar(255) DEFAULT NULL,
`user_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
如上,主要问题就在 datetime(6),其实去掉长度(6)即可,当时我就觉得特别神奇,咋 datetime 还给设置上默认长度了,看了下代码并没有呀,然后就分别用 Sqlyog 跟 navicat 导出测试,都是带着 datetime(6),然后就让小伙伴帮我测了一下, Windows 下并没有发生此类问题。
本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:https://sscai.club/index.php/archives/86/ (转载时请注明本文出处及文章链接)