从命令行将MySQL数据库转储为纯文本(CSV)备份 [英] Dump a mysql database to a plaintext (CSV) backup from the command line

查看:149
本文介绍了从命令行将MySQL数据库转储为纯文本(CSV)备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想避免mysqldump,因为输出的形式,只有方便mysql读取。 CSV似乎更普遍(每个表一个文件是好的)。但如果有mysqldump的优势,我都耳朵。此外,我想要的东西,我可以从命令行(linux)运行。如果这是一个mysql脚本,指向如何做这样的事情的指针将是有帮助的。

I'd like to avoid mysqldump since that outputs in a form that is only convenient for mysql to read. CSV seems more universal (one file per table is fine). But if there are advantages to mysqldump, I'm all ears. Also, I'd like something I can run from the command line (linux). If that's a mysql script, pointers to how to make such a thing would be helpful.

推荐答案

并且您的数据不是二进制,请使用 mysql 命令的 -B 选项。使用此选项,它将生成TSV(制表符分隔)文件,可以很容易导入到Excel等:

If you can cope with table-at-a-time, and your data is not binary, use the -B option to the mysql command. With this option it'll generate TSV (tab separated) files which can import into Excel, etc, quite easily:

% echo 'SELECT * FROM table' | mysql -B -uxxx -pyyy database

或者,如果您可以直接访问服务器的文件系统,请使用 SELECT INTO OUTFILE 可以生成真实的CSV文件:

Alternatively, if you've got direct access to the server's file system, use SELECT INTO OUTFILE which can generate real CSV files:

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

这篇关于从命令行将MySQL数据库转储为纯文本(CSV)备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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