因为需要,在两台机子上跑一个项目。一台机子安装的是mysql 5.1,另外一台是mysql5.0。
当在5.1的测试机上跑通后,拉到了正式的5.0上,一行醒目的 严重:
java.sql.BatchUpdateException: 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 'log(log_id bigint not null auto_increment,user_id bigint not null,action varchar' at line 1
原建表的sql:
create table storage
(
storage_id bigint not null,
log_id bigint not null,
content longblob,
primary key (storage_id)
);
进入mysql 命令,运行此脚本,正常。修改排版,用String sql 引用:
create table log(log_id bigint not null auto_increment,user_id bigint not null,action varchar(50) not null,time datetime not null,description longtext,primary key(log_id));
将其复制到命令运行,出错!错误同上!郁闷。。
但是相同的语句在mysql5.1中正常运行!
坑爹的发现:
create table log (log_id bigint not null auto_increment,user_id bigint not null,action varchar(50) not null,time datetime not null,description longtext,primary key(log_id));
table 后面的空格!!!在跑!建表成功!
原来mysql5.1 是支持 table(.....) 而 mysql5.0是需要规范的写table (....)
最后,奉劝大家,注意规范,尤其空格!