Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

What is the best way to backup a database in MySql

We have been working with MySql version 5.0.91 and wanted to know how to make a full backup of a specific database
Avatar of jana
jana
Flag of United States of America image

ASKER

FYI:

The tools we have is Workbench 6.2 and PHPcoder for PHP (just incase PHP is better way to go)
Avatar of Julian Hansen
Do you want the backup to run automatically or manually.

There is always mysqldump - which can be scripted to dump the database regularly.
Avatar of jana

ASKER

manually.
You can use the Data Export functionality in Workbench

Other tools like Heidi and SQLYog also have export functionality

The following will do it as well. Remember to prefix with path if mysqldump is not in the path

mysqldump -h server -u username -p databasename > database_dump.sql

Open in new window

Enter password when prompted and you are done.
Avatar of jana

ASKER

In workbench, is it Server >> Data Export (see pic below), is this correct?

User generated imageUser generated image
Note that we circle in red to know if that is correct to go.  

Also, if wanted to backup triggers and procedures, just mark them?

Lastly, where do we execute mysqldump?

please advice
Yup - I would change to a self-contained file though - easier to move around / archive etc

So under Export options just click the bottom radio - self contained file.
Avatar of jana

ASKER

Thanx!

What about "mysqldump", where do we execute it?
Mysqldump is run from the command line / terminal

You can also put it in a batch file / shell script and have a scheduler / cron job kick it off.
Avatar of madunix
madunix

1 0 * * * /root/MysqlScripts/MysqlDumpScript.sh

[root@sdc MysqlScripts]# cat MysqlDumpScript.sh 
mysqldump -u backup --password=xxxxxx --all-databases --add-locks > /root/MysqlScripts/mysqldump.db

Open in new window

Or you could have this script; set the permissions for the script carefully
#!/bin/sh
Today="`date +%m%d%y%H%M`"
mysqldump -uUserBackup -pYourPassword --all-databases | gzip -cq > /path/to/storage/sqldmp$Today.gz

Open in new window

Avatar of jana

ASKER

Please excuse our ignorance, how do we get to the command line / terminal; is this CMD or DOS prompt?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Thanx!!!
You are welcome thanks for the points.