SQL命令行错误

时间:2013-07-15 11:22:59

标签: mysql mysql-error-1064 dbforge

我试图使用命令行将表添加到MySQL中的数据库:

mysql -u Jon -p testdb --password=password < "C:\Users\Jon\Documents\Summer\Do\SQL\root.sql"

但是,当我输入上述内容时出现错误:

ERROR 1064 (42000) at line 12: 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 'VARCHAR(255) DEFAULT NULL, Clearing VARCHAR(255) DEFAULT NULL, Globex VARCH' at line 2

我使用dbForge创建了一个名为root.sql的SQL文件:

SET NAMES 'utf8';

USE testdb;

DROP TABLE IF EXISTS roottable;
CREATE TABLE roottable 
  (
    ProductName VARCHAR(255) DEFAULT NULL,
    Clearing VARCHAR(255) DEFAULT NULL,
    Globex VARCHAR(255) DEFAULT NULL,
    IsActive VARCHAR(255) DEFAULT NULL,
    FloorId VARCHAR(255) DEFAULT NULL,
    GroupId VARCHAR(255) DEFAULT NULL,
    SubGroup VARCHAR(255) DEFAULT NULL,
    ConversionFactor VARCHAR(255) DEFAULT NULL,
    Id INT PRIMARY KEY AUTO_INCREMENT
  )
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;

2 个答案:

答案 0 :(得分:1)

这可能很有趣,但尝试将SQL文件保存为utf8,使用notepad.exe打开它,然后保存为并选择utf-8然后运行查询。 试一试。

答案 1 :(得分:0)

我认为此代码应如下所示:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

CREATE SCHEMA IF NOT EXISTS `testdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `testdb`;

DROP TABLE IF EXISTS `roottable`;
CREATE TABLE `testdb`.`roottable`
  (
    `ProductName` VARCHAR(255) DEFAULT NULL,
    `Clearing` VARCHAR(255) DEFAULT NULL,
    `Globex` VARCHAR(255) DEFAULT NULL,
    `IsActive` VARCHAR(255) DEFAULT NULL,
    `FloorId` VARCHAR(255) DEFAULT NULL,
    `GroupId` VARCHAR(255) DEFAULT NULL,
    `SubGroup` VARCHAR(255) DEFAULT NULL,
    `ConversionFactor` VARCHAR(255) DEFAULT NULL,
    `Id` INT NOT NULL AUTO_INCREMENT,
     PRIMARY KEY (`Id`) 
  )
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;