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

查看:45
本文介绍了从命令行将 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.

推荐答案

如果你可以处理 table-at-a-time,并且你的数据不是二进制的,使用 -B 选项来mysql 命令.使用此选项,它将生成可以很容易地导入 Excel 等的 TSV(制表符分隔)文件:

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天全站免登陆