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

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

    Two line PowerShell answer:

    # Store in variable
    $Global:csv = (mysql -uroot -p -hlocalhost -Ddatabase_name -B -e "SELECT * FROM some_table") `
    | ConvertFrom-Csv -Delimiter "`t"
    
    # Out to csv
    $Global:csv | Export-Csv "C:\temp\file.csv" -NoTypeInformation
    

    Boom-bata-boom

    -D = the name of your database

    -e = query

    -B = tab-delimited

提交回复
热议问题