Home > Database > Mysql Tutorial > How to Export MySQL Data to Plaintext CSV Backups Using Command Line Tools?

How to Export MySQL Data to Plaintext CSV Backups Using Command Line Tools?

DDD
Release: 2024-10-30 10:41:27
Original
448 people have browsed it

How to Export MySQL Data to Plaintext CSV Backups Using Command Line Tools?

Exporting MySQL Data to Plaintext CSV Backups using Command Line Tools

Backing up database content in a convenient and universal format is essential for data protection. While mysqldump remains a popular choice, users often seek alternatives that provide more flexibility and compatibility. This article provides two command-line methods for exporting MySQL data to plain text CSV backups.

Method 1: Using -B Option

If your data does not contain binary values and you do not require a single CSV file for all tables, you can utilize the -B option of the mysql command. This option generates tab-separated (TSV) files, which are easily importable into tools like Excel:

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

Method 2: Using SELECT INTO OUTFILE

For direct access to the server's file system, the SELECT INTO OUTFILE statement creates CSV files with customizable field and line delimiters. This method provides a more controlled CSV output:

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

By selecting one method based on your specific requirements, you can effectively export MySQL data to plaintext CSV backups from the command line, ensuring data preservation and accessibility.

The above is the detailed content of How to Export MySQL Data to Plaintext CSV Backups Using Command Line Tools?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template