简体   繁体   English

使用EF迁移历史记录表中的二进制数据还原mysqldump

[英]Restore mysqldump with binary data from EF migration history table

I'm trying to restore a database from a dump generated with mysqldump . 我正在尝试从mysqldump生成的转储中还原数据库。 However it contains binary data. 但是,它包含二进制数据。

I made an mysqldump of a database which have an entity framework migration history table. 我做了一个数据库的mysqldump ,其中有一个实体框架迁移历史表。

mysqldump.exe --opt --user=root foo > dump.sql mysqldump.exe --opt --user = root foo> dump.sql

This table has a column with binary data (longblob) and it's causing me issues when trying to restore. 该表的一列包含二进制数据(longblob),在尝试还原时导致我出现问题。

I first tried to restore via WorkBench, but it failed. 我首先尝试通过WorkBench进行还原,但是失败了。 I then copied the command that workbench used and ran it manually. 然后,我复制了工作台使用的命令并手动运行它。 It obviously had the same result. 显然有相同的结果。

mysql.exe --protocol=tcp --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments --database=foo < dump.sql mysql.exe --protocol = tcp --host = localhost --user = root --port = 3306 --default-character-set = utf8 --comments --database = foo <dump.sql

ERROR: ASCII '\\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. 错误:语句中出现了ASCII'\\ 0',但这是不允许的,除非启用了选项--binary-mode且mysql以非交互模式运行。 Set --binary-mode to 1 if ASCII '\\0' is expected. 如果需要ASCII'\\ 0',则将--binary-mode设置为1。 Query: ' ■-'. 查询:“■-”。

It tells me to add --binary-mode=1 , so I did. 它告诉我添加--binary-mode=1 ,所以我做到了。

mysql.exe --binary-mode=1 --protocol=tcp --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments --database=foo < dump.sql mysql.exe --binary-mode = 1 --protocol = tcp --host = localhost --user = root --port = 3306 --default-character-set = utf8 --comments --database = foo <转储。 sql

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; 第1行的错误1064(42000):您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '??-' at line 1 检查与您的MySQL服务器版本相对应的手册,以在第1行的'??-'附近使用正确的语法

But it still doesn't work. 但这仍然行不通。 Then I tried to find ??- in the dump file but couldn't. 然后,我尝试在转储文件中找到??-但找不到。 I read somewhere that I shouldn't change the charset. 我读过某个地方,我不应该更改字符集。 So I tried removing --default-character-set=utf8 from the command. 所以我尝试从命令中删除--default-character-set=utf8

mysql.exe --binary-mode=1 --protocol=tcp --host=localhost --user=root --port=3306 --comments --database=foo < dump.sql mysql.exe --binary-mode = 1 --protocol = tcp --host = localhost --user = root --port = 3306 --comments --database = foo <dump.sql

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; 第1行的错误1064(42000):您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ■-' at line 1 检查与您的MySQL服务器版本相对应的手册,以在第1行的“-”附近使用正确的语法

Now I'm able to find ■- in the dump file, but it doesn't really help me :/ 现在,我可以在转储文件中找到■- ,但是它并没有真正帮助我:/


Content of dump.sql dump.sql内容

-- MySQL dump 10.13  Distrib 5.7.7-rc, for Win64 (x86_64)
--
-- Host: localhost    Database: foo
-- ------------------------------------------------------
-- Server version   5.7.7-rc-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 `__migrationhistory`
--

DROP TABLE IF EXISTS `__migrationhistory`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `__migrationhistory` (
  `MigrationId` varchar(100) NOT NULL,
  `ContextKey` varchar(200) NOT NULL,
  `Model` longblob NOT NULL,
  `ProductVersion` varchar(32) NOT NULL,
  PRIMARY KEY (`MigrationId`,`ContextKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `__migrationhistory`
--

LOCK TABLES `__migrationhistory` WRITE;
/*!40000 ALTER TABLE `__migrationhistory` DISABLE KEYS */;
INSERT INTO `__migrationhistory` VALUES ('123456789012345_InitialCreate',

Found the problem! 发现了问题!

I was running mysqldump via a powershell script which was causing the dump.sql file to be encoded incorrectly. 我正在通过Powershell脚本运行mysqldump ,这导致dump.sql文件被错误地编码。

Switched to a bat script instead and now it works 改用蝙蝠脚本,现在可以使用了

do not use IO redirect, use mysqldump option instead. 不要使用 IO重定向,而是使用mysqldump选项。

-r, --result-file=name Direct output to a given file. -r,--result-file = name直接输出到给定文件。 This option should be used in systems (eg, DOS, Windows) that use carriage-return linefeed pairs (\\r\\n) to separate text lines. 此选项应在使用回车换行符(\\ r \\ n)分隔文本行的系统(例如DOS,Windows)中使用。 This option ensures that only a single newline is used. 此选项可确保仅使用一个换行符。

the OS IO redirect will change the encoding of the result file. OS IO重定向将更改结果文件的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM