Dump a mysql database to a plaintext (CSV) backup from the command line

前端 未结 10 1055
广开言路
广开言路 2020-11-28 19:26

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 ar

10条回答
  •  被撕碎了的回忆
    2020-11-28 19:53

    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
    

    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
    

提交回复
热议问题