使用来自 EF 迁移历史记录的二进制数据恢复 mysqldump table
Restore mysqldump with binary data from EF migration history table
我正在尝试从 mysqldump
生成的转储中恢复数据库。但是它包含二进制数据。
我制作了一个 mysqldump
的数据库,它有 entity framework 迁移历史 table。
mysqldump.exe --opt --user=root foo > dump.sql
这个 table 有一个包含二进制数据 (longblob) 的列,它在尝试恢复时给我带来了问题。
我首先尝试通过 WorkBench 恢复,但失败了。然后我复制了 workbench 使用的命令并手动复制了 运行 。显然有相同的结果。
mysql.exe --protocol=tcp --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments --database=foo < dump.sql
ERROR: ASCII '[=20=]' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '[=20=]' is expected. Query: ' ■-'.
它告诉我添加 --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
ERROR 1064 (42000) at line 1: 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 '??-' at line 1
但是还是不行。然后我试图在转储文件中找到 ??-
但找不到。我在某处读到我不应该更改字符集。所以我尝试从命令中删除 --default-character-set=utf8
。
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; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ■-' at line 1
现在我可以在转储文件中找到 ■-
,但这并没有真正帮助我:/
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',
找到问题了!
我 运行 mysqldump
通过 powershell 脚本导致 dump.sql 文件编码不正确。
改为使用 bat 脚本,现在可以使用了
不要使用 IO 重定向,而是使用 mysqldump 选项。
-r, --result-file=name
Direct output to a given file. This option should be used
in systems (e.g., DOS, Windows) that use carriage-return
linefeed pairs (\r\n) to separate text lines. This option
ensures that only a single newline is used.
OS IO 重定向将更改结果文件的编码。
我正在尝试从 mysqldump
生成的转储中恢复数据库。但是它包含二进制数据。
我制作了一个 mysqldump
的数据库,它有 entity framework 迁移历史 table。
mysqldump.exe --opt --user=root foo > dump.sql
这个 table 有一个包含二进制数据 (longblob) 的列,它在尝试恢复时给我带来了问题。
我首先尝试通过 WorkBench 恢复,但失败了。然后我复制了 workbench 使用的命令并手动复制了 运行 。显然有相同的结果。
mysql.exe --protocol=tcp --host=localhost --user=root --port=3306 --default-character-set=utf8 --comments --database=foo < dump.sql
ERROR: ASCII '[=20=]' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '[=20=]' is expected. Query: ' ■-'.
它告诉我添加 --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
ERROR 1064 (42000) at line 1: 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 '??-' at line 1
但是还是不行。然后我试图在转储文件中找到 ??-
但找不到。我在某处读到我不应该更改字符集。所以我尝试从命令中删除 --default-character-set=utf8
。
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; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ■-' at line 1
现在我可以在转储文件中找到 ■-
,但这并没有真正帮助我:/
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',
找到问题了!
我 运行 mysqldump
通过 powershell 脚本导致 dump.sql 文件编码不正确。
改为使用 bat 脚本,现在可以使用了
不要使用 IO 重定向,而是使用 mysqldump 选项。
-r, --result-file=name Direct output to a given file. This option should be used in systems (e.g., DOS, Windows) that use carriage-return linefeed pairs (\r\n) to separate text lines. This option ensures that only a single newline is used.
OS IO 重定向将更改结果文件的编码。