This is what I tend to use for a simple MySQL database backup script… I wanted to post this so I can look it up when I need it. There are probably better ways to do this (tell me about them!) but this works for me.
#!/bin/bash DT=`date +"%Y%m%d%H%M%S"` mysqldump -u [USERNAME] -p[PASSWORD] [DATABASENAME] > /home/backups/[DATABASENAME]-$DT.dump gzip /home/backups/[DATABASENAME]-$DT.dump
Substitute your MySQL user for [USERNAME]. (There should be a space between the ‘-u’ and the [USERNAME])
Substitute your MySQL user’s password for [PASSWORD]. (There should not be a space between the -p and the [PASSWORD])
Substitute your MySQL user’s database for p[DATABASENAME].
Each time you run it, it will get the date with the year, month, day, hours, minutes, seconds, and use it in the name. So %Y%m%d%H%M%S would produce something like 20100711090854. If you are running one backup per day, you could shorten it to %Y%m%d.
This would put the files in the /home/backups directory. Set this to wherever you want the files to go.
The gzip command compresses the dumped database file. If you don’t want to compress it (and save disk space) then don’t use it.
(BTW, you don’t type the [ brackets ]. They are just there to highlight the words you need to fill in.)