zoukankan      html  css  js  c++  java
  • linux5.6以下版本的不兼容问题

    之前一直用的都是mysql5.6版本,最近突然使用到了mysql5.1版本,于是在导入数据的时候便出现了很多由于版本不兼容的问题。

    1.mysql5.1没有datetime类型,所以对于时间类型,只能使用timestamp

    例:

    1 `FRecordTime` datetime DEFAULT CURRENT_TIMESTAMP

    需要改为

    1 `FRecordTime` timestamp DEFAULT CURRENT_TIMESTAMP,

    2.mysql5.6版本以下不允许一个表有两个current_timestamp

    例:

    当你创建该表时:

    1 CREATE TABLE `example` (
    2   `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    3   `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    4   `lastUpdated` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
    5   PRIMARY KEY (`id`)
    6 ) ENGINE=InnoDB;

    会出错,错误信息为:

    1 ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.

    意思是只能有一个带CURRENT_TIMESTAMP的timestamp列存在。其实在mysql5.5中存在这么一句话:

     One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column,
    as the auto-update value, or both. It is not possible to have the current timestamp be the
    default value for one column and the auto-update value for another column.

    而在mysql5.6中则进行了修改:

     Previously, at most one TIMESTAMP column per table could be automatically initialized or updated to the current date and time.
    This restriction has been lifted. Any TIMESTAMP column definition can have any combination
    of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses.
    In addition, these clauses now can be used with DATETIME column definitions.
    For more information, see Automatic Initialization and Updating for TIMESTAMP and DATETIME.

    即允许了这种情况出现。

    解决方法:

    可以用触发器实现上述表的创建:

     1 CREATE TABLE `example` (
     2   `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
     3   `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
     4   `lastUpdated` DATETIME NOT NULL,
     5   PRIMARY KEY (`id`)
     6 ) ENGINE=InnoDB;
     7 DROP TRIGGER IF EXISTS `update_example_trigger`;
     8 DELIMITER //
     9 CREATE TRIGGER `update_example_trigger` BEFORE UPDATE ON `example`
    10  FOR EACH ROW SET NEW.`lastUpdated` = NOW()
    11 //
    12 DELIMITER ;

    3.mysql5.1的limit语句后面只允许跟常量不允许是变量

    在存储过程的中,mysql5.6允许limit后面直接跟着输入参数,但是mysql5.1只允许limit后面跟着常量。

    解决方法:

    1)采用动态的方式

    1 PREPARE stmt1 FROM 'select * from users LIMIT ?,?';
    2 SET @a = ino;
    3 SET @b = pagecount
    4 EXECUTE stmt1 USING @a, @b;

    2)将变量事先转换为字符:

    1 set @dd=conact('select * from users LIMIT',ino,pagecount)
    2 PREPARE stmt1 FROM dd
    3 EXECUTE stmt1
  • 相关阅读:
    2012.05.17
    一些记录
    2012.09.09 js
    2012.05.24 jq Tab
    2012.10.08 关于 开发计划制定、项目管理、功能设计 的想法记录
    2012.05.21 jq Tab
    关于工作状态
    ImageWaterMark参数说明
    关于拼接邮件在存储过程中
    关于使用HtmlAgilityPack
  • 原文地址:https://www.cnblogs.com/fnlingnzb-learner/p/7066865.html
Copyright © 2011-2022 走看看