blog.up-link.ro android bsd linux unix & open-source world

14Apr/100

How To Export MySQL data to CSV file

In this article I'll show you how to export MySQL database to a CSV file.

1. Export MySQL data to CSV file using a simple "SELECT" statement

If you want to export your mysql table into a csv file you need to run the following command:

# mysql -u username -ppassword database -e "SELECT * INTO OUTFILE '/tmp/filename.csv'  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'  LINES TERMINATED BY '\r\n' FROM table;"

username is your mysql username
password is your mysql password
database is your mysql database
table is the table you want to export

You can find the exported CSV file in the /tmp directory. The name of the file is filename.csv.

2. Export MySQL data to CSV file using "sed"

If you want to export your mysql table into a csv file you need to run the following command:

Print This Post Print This Post