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


这应该可以工作:

# 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

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


mysqldump --no-create-info ...

你还可以用:

——跳过触发器:如果你正在使用触发器 ——no-create-db:如果你正在使用——databases…选项 ——compact:如果你想去掉额外的注释


只需将数据转储为带分隔符的文本格式。


尝试转储到一个带分隔符的文件。

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

当试图使用接受的答案导出数据时,我得到了一个错误:

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'

如上所述:

mysqldump --no-create-info

将导出数据,但它也将导出create触发器语句。如果你像我一样用一个命令输出数据库结构(也包括触发器),然后使用上面的命令来获取数据,你也应该使用'——skip-triggers'。

所以如果你只想要数据:

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

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

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

至少mysql 5。要求X,但现在谁经营这些老东西。:)


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

下面的解释如下

--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).

# 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

如果你只想要INSERT查询,使用下面的方法:

Mysqldump—skip-triggers—compact—no-create-info


最好转储到一个压缩文件

mysqldump --no-create-info -u username -hhostname -p dbname | gzip > /backupsql.gz

并使用pv apt-get安装pv来监控进度

pv backupsql.gz | gunzip | mysql -uusername -hhostip -p dbname