我正在尝试将运行MySQL 5.0的服务器(将升级到5.5)的drupal数据库的mysqldump备份导入到运行MySQL 5.5.23的本地计算机上.导入失败,出现以下错误:
ERROR 1100 (HY000) at line 11084: Table 'search_index' was not locked with LOCK TABLES
当我打开11084行的备份时,我得到的是:
LOCK TABLES `sessions` WRITE;
/*!40000 ALTER TABLE `sessions` DISABLE KEYS */;
INSERT INTO `sessions` VALUES ...
-- MySQL dump 10.11
--
-- Host: localhost Database: drupal
-- ------------------------------------------------------
-- Server version 5.0.77-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `search_index`
--
DROP TABLE IF EXISTS `search_index`; <=== LINE 11084
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `search_index` (
`word` varchar(50) NOT NULL default '',
`sid` int(10) unsigned NOT NULL default '0',
`type` varchar(16) default NULL,
`score` float default NULL,
UNIQUE KEY `word_sid_type` (`word`,`sid`,`type`),
KEY `sid_type` (`sid`,`type`),
KEY `word` (`word`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
我检查了其他语句,通常INSERT语句后跟UNLOCK TABLES;.因此,如果我对mysqldump文件进行以下修改,问题就解决了:
INSERT INTO `sessions` VALUES ...
UNLOCK TABLES; <=== ADDED LINE
-- MySQL dump 10.11
[...]
DROP TABLE IF EXISTS `search_index`;
我不知道那里有什么问题,但整个注释块开头–MySQL转储10.11与mysqldump文件开头的那个相同,看起来mysqldump在编写INSERT INTO会话语句时启动了一个新的转储用UNLOCK TABLES没有正确关闭;
有人知道这里发生了什么吗?
解决方法:
我最初的猜测是,当创建mysqldump文件时,没有使用选项single-transaction.
根据single-transaction上的MySQL文档
The –single-transaction option and the –lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly.
您嵌入了UNLOCK TABLES的事实;手动进入转储显示在首次创建mysqldump时都没有调用任何选项.因此,在重新加载时,这个错误引起了它的丑陋头脑.