如何将临时MySQL表转储到文件中? [英] How to dump temporary MySQL table into a file?

查看:119
本文介绍了如何将临时MySQL表转储到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在磁盘上的文件(.sql文件,类似于mysqldump创建的文件)中创建转储/导出/保存临时MySQL表的方法?

Is there a way to create a dump/export/save a temporary MySQL table into a file on disk(.sql file that is, similar to one that is created by mysqldump)?

推荐答案

对不起,我第一次没有正确阅读该问题……无论如何,我能想到的最好的就是使用SELECT ... INTO OUTFILE语句,就像这样:

Sorry, I did not read the question properly the first time around... at any rate, the best I can think of is using the SELECT ... INTO OUTFILE statement, like this:

SELECT * INTO OUTFILE 'result.csv'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM temp_table;

这确实有很多限制,例如,它仅转储原始数据而不包括字段头.我发现可能有用或可能无效的另一件事是SHOW CREATE TABLE语句.如果您找到结合这两个语句的输出的某种方式,则可能能够获得由我的以下命令生成的正确的转储"文件.

This does have many limitations thought, for instance, it only dumps the raw data without including the field headers. The other thing I found that may or may not be of use is the SHOW CREATE TABLE statement. If you can find some way of combining the output from these two statements, you may be able to get a proper "dump" file as produced by my command below.

您应该能够使用mysqldump应用程序:

You should be able to use the mysqldump application:

mysqldump --databases temptable > file.sql

这将使表以CREATE减速度转储.

This will dump the table with CREATE decelerations.

这篇关于如何将临时MySQL表转储到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆