I have a sql script, generated by MySQL Workbench, which creates my database / tables etc. It is of the form
-- 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;
...
And so on, creating a number of tables and then inserting a few values.
However, if I try to run this, either by
mysql -u root --password=xxx < schema.sql
or
source /path/to/schema.sql;
in the mysql shell, I get the following
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
...
There are 10 successful queries, and the rest all fail. Running again gives the same (but with warnings, since some tables already exist now).
How do I stop this error 2013 and create all of my tables?
Update
I checked the log files, and found a series of logs of this form in /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.
However, the only help on the net I can find is when this error occurs due to manually moving the files (not what I did, although I did take a backup before this problem started).