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

前端 未结 10 1036
广开言路
广开言路 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:41

    The select into outfile option wouldn't work for me but the below roundabout way of piping tab-delimited file through SED did:

    mysql -uusername -ppassword -e "SELECT * from tablename" dbname | sed 's/\t/","/g;s/^/"/;s/$/"/' > /path/to/file/filename.csv
    

提交回复
热议问题