mysql创建脚本,错误给我带来麻烦

标签 mysql database scripting

使用 mySQL 版本 5.0.51a-24+lenny4。以下脚本有什么问题?我不断收到以下错误:

ERROR 1064 (42000): 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 'mjla_creat.sql' at line 1

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';


-- -----------------------------------------------------
-- Table `mjla_db`.`ClassTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`ClassTable` (
  `classId` VARCHAR(20) NOT NULL COMMENT 'This columns is used to store the class identifier.' ,
  `className` VARCHAR(10) NOT NULL COMMENT 'Holds the name of the class. for example.' ,
  `classSection` VARCHAR(5) NOT NULL COMMENT 'Holds the section label. Used to designate which section the class is.' ,
  `classSemester` VARCHAR(2) NOT NULL COMMENT 'This is used to designate which semester. This is given two character positions incase a school needed to determine which semester within the semester.' ,
  `classYear` VARCHAR(4) NOT NULL COMMENT 'This is for the year of the class.' ,
  `teacherId` VARCHAR(20) NOT NULL ,
  PRIMARY KEY (`classId`) ,
  UNIQUE INDEX `classId_UNIQUE` (`classId` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`TeacherTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`TeacherTable` (
  `teacherId` VARCHAR(20) NOT NULL COMMENT 'This is the teacher id. This table will have to be pre-populated by the administrator with teacher id\'s and their passwords.' ,
  `teacherPassword` VARCHAR(32) NOT NULL COMMENT 'Stores the password as md5.' ,
  PRIMARY KEY (`teacherId`) ,
  UNIQUE INDEX `teacherId_UNIQUE` (`teacherId` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`QuizTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`QuizTable` (
  `classId` VARCHAR(20) NOT NULL COMMENT 'FK related to the ClassTable. This way each Class in the ClassTable is associated with its quiz in the QuizTable.' ,
  `quizId` INT NOT NULL AUTO_INCREMENT COMMENT 'This is the quiz number associated with the quiz.' ,
  `quizObject` BLOB NOT NULL COMMENT 'This is the actual quiz object.' ,
  `quizEnabled` TINYINT(1)  NOT NULL ,
  PRIMARY KEY (`classId`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`StudentTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`StudentTable` (
  `studentId` VARCHAR(20) NOT NULL ,
  `lastName` VARCHAR(45) NOT NULL ,
  `firstName` VARCHAR(45) NOT NULL ,
  `studentPassword` VARCHAR(32) NOT NULL ,
  PRIMARY KEY (`studentId`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`StudentRecordTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`StudentRecordTable` (
  `classId` VARCHAR(20) NOT NULL ,
  `studentId` VARCHAR(20) NOT NULL ,
  `quizGrade` TINYINT NULL ,
  `quizId` INT NOT NULL AUTO_INCREMENT ,
  PRIMARY KEY (`classId`) )
ENGINE = InnoDB;



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

谢谢!

最佳答案

near 'mjla_creat.sql' at line 1

此字符串未出现在您显示的 SQL 脚本中,因此错误不在您的 SQL 脚本中。这可能是您用来调用脚本的命令出错。

您可以从 shell 提示符调用(您可能还需要其他选项来连接到数据库):

$ mysql mjla < mjla_creat.sql 

或者您可以从 MySQL 监视器调用它:

mysql> \. mjla_creat.sql

或者

mysql> source mjla_creat.sql

关于mysql创建脚本,错误给我带来麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7698126/

相关文章:

javascript - NodeJS 和 Mysql 查询获取

email - 使用脚本语言动态处理传入的电子邮件数据 -> 数据库

python - mysql.connector.errors.InternalError : Unread result found during UPDATE

mysql - 检索表中的重复项并显示它们

Mysql ORDER BY 和 LIMIT 慢查询

linux - 在分别打印文件名和行时查找文件中的最大行?

linux - 捕获 bash 命令的输出,解析它并存储到不同的 bash 变量中

php - Mysql在Mysql客户端查询成功但通过PHP查询失败

mysql - 连接 2 表 Mysql 的查询中的计算

mysql - 每次 COUNT() 函数,还是存储值并将其递增 1?