我有一个由MySQL Workbench生成的sql脚本,它创建了我的数据库/表格等。它的格式为
-- MySQL Script generated by MySQL Workbench
-- 01/29/15 11:35:28
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
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';
-- -----------------------------------------------------
-- Schema dbname
-- -----------------------------------------------------
-- Some description
-- -----------------------------------------------------
-- Schema dbname
--
-- Some description
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `dbname` ;
-- -----------------------------------------------------
-- Table `dbname`.`countries`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `dbname`.`countries` (
`name` VARCHAR(40) NOT NULL,
PRIMARY KEY (`name`))
ENGINE = InnoDB;
SHOW WARNINGS;
...
依此类推,创建一些表,然后插入一些值。
但是,如果我试图通过
运行它mysql -u root --password=xxx < schema.sql
或
source /path/to/schema.sql;
在mysql shell中,我得到以下内容
Query OK, 0 rows affected (0.00 sec)
...
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.01 sec)
Empty set (0.00 sec)
...
Query OK, 0 rows affected (0.01 sec)
Empty set (0.00 sec)
ERROR 2013 (HY000): Lost connection to MySQL server during query
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
ERROR:
Can't connect to the server
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
ERROR:
Can't connect to the server
...
有10个成功的查询,其余的都失败了。再次运行会给出相同的结果(但有警告,因为现在已经存在一些表)。
如何停止此错误2013并创建所有表格?
更新
我检查了日志文件,并在/var/log/mysql/error.log
150130 11:55:32 [ERROR] Cannot find or open table playwhoo/joinRequests from
the internal data dictionary of InnoDB though the .frm file for the
table exists. Maybe you have deleted and recreated InnoDB data
files but have forgotten to delete the corresponding .frm files
of InnoDB tables, or you have moved .frm files to another database?
or, the table contains indexes that this version of the engine
doesn't support.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
how you can resolve the problem.
然而,我能找到的唯一帮助是因为手动移动文件而发生此错误(不是我做的,虽然我在此问题开始之前就做了备份)。
答案 0 :(得分:0)
最后在拆开我的schema.sql
之后解决了它,看看为什么它在那时失败了。
原来我没有说出任何约束。也就是说,它们都是这样的:
CONSTRAINT ``
FOREIGN KEY (`user`)
REFERENCES `dbname`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
MySQL对此异常,并生成error 121。在MySQL命令行中逐个输入命令时,这一点很明显。但是,当批量完成时,整件事情就会崩溃并给出了神秘的MySQL server has gone away
。
我仍然有兴趣知道(在下面的评论中),如果有正确错误的传播缺乏的正当理由。为什么不说错误121而不是连接失败(就像它一样)?