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

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

Linda Hamilton
Release: 2024-11-01 01:11:28
Original
786 people have browsed it

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template