简体   繁体   English

从单个表的查询备份恢复mysql

[英]Backup restore mysql from query of single table

I have a database with three tables . 我有一个包含三个表的数据库。 I want to create a backup file of some records in the second table : 我想在第二个表中创建一些记录的备份文件:

mysqldump --opt --user=${USER} --password=${PASS} --databases ${DATABASE} --where="id = $1" mydb Table2 > FILE.sql

the problem is in the restore by using this code . 问题在于使用此代码进行还原。

mysql --user=${USER} --password=${PASS}  ${DATABASE} < FILE.sql

It deletes the entire database and inserts I only selected records from the previous code . 它删除整个数据库并插入我以前代码中只选择的记录。 I wish only the selected records restore without deleting the rest . 我希望只删除所选记录而不删除其余记录。

You should try using the --skip-add-drop-table option when using mysqldump. 使用mysqldump时,应该尝试使用--skip-add-drop-table选项。

http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

This would prevent a drop table entry being added to the sql export. 这样可以防止将删除表条目添加到sql导出中。

You are using the [--databases][1] flag which is used when dumping several databases and should not be used when you want to dump only a single table. 您正在使用[--databases][1]标志,该标志在转储多个数据库时使用,并且在您只想转储单个表时不应使用。

Dump several databases. 转储几个数据库。 Normally, mysqldump treats the first name argument on the command line as a database name and following names as table names. 通常,mysqldump将命令行上的第一个名称参数视为数据库名称,将后续名称视为表名称。 With this option, it treats all name arguments as database names. 使用此选项,它将所有名称参数视为数据库名称。 CREATE DATABASE and USE statements are included in the output before each new database. CREATE DATABASE和USE语句包含在每个新数据库之前的输出中。

Avoid using that argument and for good measure use --no-create-info or simply -t instead to make sure create table / drop table commands are not in the dump file 避免使用该参数并使用--no-create-info或简单地使用-t来确保create table / drop table命令不在转储文件中

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

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