MySQL 仅 mysqldump 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5109993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:54:19  来源:igfitidea点击:

mysqldump data only

mysqlmysqldump

提问by Lizard

I am looking for the syntax for dumping all data in my mysql database. I don't want any table information.

我正在寻找在我的 mysql 数据库中转储所有数据的语法。我不想要任何表信息。

回答by matei

mysqldump --no-create-info ...

Also you may use:

你也可以使用:

  • --skip-triggers: if you are using triggers
  • --no-create-db: if you are using --databases ...option
  • --compact: if you want to get rid of extra comments
  • --skip-triggers: 如果你使用触发器
  • --no-create-db:如果您使用--databases ...选项
  • --compact: 如果你想去掉多余的评论

回答by Ish

This should work:

这应该有效:

# To export to file (data only)
mysqldump -u [user] -p[pass] --no-create-info mydb > mydb.sql

# To export to file (structure only)
mysqldump -u [user] -p[pass] --no-data mydb > mydb.sql

# To import to database
mysql -u [user] -p[pass] mydb < mydb.sql

NOTE:there's no space between -p& [pass]

注意:-p&之间没有空格[pass]

回答by Angelin Nadar

 >> man -k  mysqldump [enter in the terminal]

you will find the below explanation

你会发现下面的解释

--no-create-info, -t

Do not write CREATE TABLE statements that re-create each dumped table. Note This option does not not exclude statements creating log file groups or tablespaces from mysqldump output; however, you can use the --no-tablespaces option for this purpose.

--no-data, -d

Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the CREATE TABLE statement for the table (for example, to create an empty copy of the table by loading the dump file).

--no-create-info, -t

不要编写重新创建每个转储表的 CREATE TABLE 语句。注意 此选项不排除从 mysqldump 输出中创建日志文件组或表空间的语句;但是,您可以为此使用 --no-tablespaces 选项。

--无数据,-d

不写入任何表行信息(即不转储表内容)。如果您只想转储表的 CREATE TABLE 语句(例如,通过加载转储文件创建表的空副本),这很有用。

# To export to file (data only)
mysqldump -t -u [user] -p[pass] -t mydb > mydb_data.sql

# To export to file (structure only)
mysqldump -d -u [user] -p[pass] -d mydb > mydb_structure.sql

回答by Jonathan

If you just want the INSERT queries, use the following:

如果您只想要 INSERT 查询,请使用以下内容:

mysqldump --skip-triggers --compact --no-create-info

mysqldump --skip-triggers --compact --no-create-info

回答by wuzer

Would suggest using the following snippet. Works fine even with huge tables (otherwise you'd open dump in editor and strip unneeded stuff, right? ;)

建议使用以下代码段。即使有大表也能正常工作(否则你会在编辑器中打开转储并删除不需要的东西,对吧?;)

mysqldump --no-create-info --skip-triggers --extended-insert --lock-tables --quick DB TABLE > dump.sql

At least mysql 5.xrequired, but who runs old stuff nowadays.. :)

至少需要mysql 5.x,但现在谁运行旧东西.. :)

回答by Frank Heikens

Just dump the data in delimited-text format.

只需以分隔文本格式转储数据。

回答by ed209

Try to dump to a delimited file.

尝试转储到分隔文件。

mysqldump -u [username] -p -t -T/path/to/directory [database] --fields-enclosed-by=\" --fields-terminated-by=,

回答by Ben Waine

When attempting to export data using the accepted answer I got an error:

尝试使用接受的答案导出数据时,出现错误:

ERROR 1235 (42000) at line 3367: This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table'

As mentioned above:

正如刚才提到的:

mysqldump --no-create-info

Will export the data but it will also export the create trigger statements. If like me your outputting database structure (which also includes triggers) with one command and then using the above command to get the data you should also use '--skip-triggers'.

将导出数据,但也会导出创建触发器语句。如果像我一样使用一个命令输出数据库结构(也包括触发器),然后使用上述命令获取数据,您还应该使用“--skip-triggers”。

So if you want JUST the data:

所以如果你只想要数据:

mysqldump --no-create-info --skip-triggers