Home  >  Article  >  Database  >  How Can I Dump MySQL Databases to Plaintext (CSV) Backups?

How Can I Dump MySQL Databases to Plaintext (CSV) Backups?

Linda Hamilton
Linda HamiltonOriginal
2024-11-01 01:11:28694browse

How Can I Dump MySQL Databases to Plaintext (CSV) Backups?

Dumping MySQL Databases to Plaintext (CSV) Backups Using SQL

Rather than using mysqldump, which outputs data in a format primarily designed for MySQL, you can utilize alternative methods to create universal CSV backups.

TSV Export:

To generate tab-separated (TSV) files compatible with Excel and other spreadsheet software, employ the -B option in MySQL. This method allows for easy data importation into external applications:

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

CSV Export:

Alternatively, if you have direct access to the server's file system, consider using SELECT INTO OUTFILE. This method generates true CSV files:

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

By using these approaches, you can createplaintext (CSV) backups from the command line, providing flexibility and compatibility with various platforms.

The above is the detailed content of How Can I Dump MySQL Databases to Plaintext (CSV) Backups?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn