A CREATE script exported by MySQL Workbench has syntax error on another computer

南笙酒味 提交于 2019-12-12 05:48:19

问题


I created a database on my computer, with MySQL 5.5 and MySQL Workbench 5.2.34 CE installed. Then i want to migrate the database to another computer, which has MySQL 5.0 installed. (I just need to migrate the schema, data are not needed)

I use the MySQL Workbench's File -> Export -> Forward Engineer SQL CREATE script to generate db.sql script and copy it to the other computer.

I type mysql < db.sql to create the database but only to receive an error.

Error occurs here:

DELIMITER $$

CREATE PROCEDURE `filedb`.`GetIncompleteFileId` (in latestFileId BIGINT UNSIGNED, in serverBits BIT(32), in fileCount SMALLINT UNSIGNED)

BEGIN
    SELECT `id`, `key`, `length`, `path`
    FROM
    (
        SELECT * FROM `filedb`.`fileInfo` WHERE `id` <= latestFileId
    ) AS TempTable
    WHERE (serverBits & `serverownership` NOT IN (serverBits, 0))
    ORDER BY `id` DESC
    LIMIT fileCount;
END

$$

The error is near 'fileCount; END'. If i remove the "LIMIT fileCount", the error disappears.

Anyone tells me what is the problem?


回答1:


In the MySQL 5.0 LIMIT arguments must be nonnegative integer constants, not a variables or procedure parameters. Use prepared statements to avoid this error.

From the MySQL 5.0 documentation -

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).

From the MySQL 5.5 documentation -

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions:

Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.

Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables as of MySQL 5.5.6.



来源:https://stackoverflow.com/questions/11135133/a-create-script-exported-by-mysql-workbench-has-syntax-error-on-another-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!