MySQL: how to take the backup of the database using mysqldump

Hi, I just want to take the mysql db backup using mysqldump.

Can any help.

Thanks,
EL
el123Asked:
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.

hieloCommented:
mysqldump db_name > backup-file.sql

http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
0
Michael WorshamStaff Infrastructure ArchitectCommented:
To allow for consistent reads from the database and to control character set issues, I recommend doing it like this:

mysqldump --single-transaction --result-file=db_name.sql db_name --default-character-set=utf8

Reference:
http://dev.mysql.com/doc/refman/5.0/en/backup-policy.html
0
UmeshSenior Principal Technical Support EngineerCommented:
As 'hielo' mentioned 'mysqldump' is the tool to take mysql database backup.

Also, What kind of tables do you use ? innodb or myisam? if your answer is innodb then don't forget to use --single-transaction option to get a consistent dump.. and if its myisam table then without locking you will not be getting a consistent backup...so make sure its locked before you dump...
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

UmeshSenior Principal Technical Support EngineerCommented:
Oops.. not refreshed :-)
0
el123Author Commented:
thank Gurus, my tables are all Innodb, and I want script too, so I can automate them to be taken on certain schedules
0
UmeshSenior Principal Technical Support EngineerCommented:
Try this script.. once this script is in place.. make sure you have some rotation/archiving policies..so that backups won't eat much space :-)
#!/bin/sh
 
date = `date +%Y%m%d`
 
# Simple dump
mysqldump --user=root --password=my_pwd --single-transaction \
     --all-databases > /backup_dir/backup-${date}.sql
 
# To save space..you may want to use this compressed dump...
mysqldump --user=root --password=my_pwd --single-transaction \
     --all-databases | gzip > /backup_dir/backup-${date}.sql.gz

Open in new window

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
UmeshSenior Principal Technical Support EngineerCommented:
Did you check this?
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
MySQL Server

From novice to tech pro — start learning today.