Auto Export MySQL Database to CSV File

I want to create a file that when ran will export my whole MySQL database to a csv file. Ultimately this will be done nightly. I would just like to see it done automatically rather than manually.

Any tips or tutorials to walk me through it?
BHUCAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

theGhost_k8Database ConsultantCommented:
You may use SELECT INTO OUTFILE to export single table as a CSV file. To do this for whole database, I'd recommend you to write looped shell script.

SELECT * INTO OUTFILE '/csv_files/db.tablename.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM db.tablename;

Open in new window



Even better use this and all your pain is eased:--

mysqldump --tab=/var/lib/mysql-files/ --fields-enclosed-by='"' --fields-terminated-by=',' --lines-terminated-by='\n' --all-databases

Now you will have the .txt file for each of the table under /var/lib/mysql-files
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BHUCAuthor Commented:
Thank you
0
theGhost_k8Database ConsultantCommented:
Glad that this solved your problem. Since I saw this at multiple places, I thought of writing a post about it. Read it here -> 3 ways to export from MySQL to CSV
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.