MySQL backup faq:how do I backup a MySQL database?
I can ' t speak about backing up MySQL databases that is modified twenty-four hours a day seven days a week MySQL databases I currently work with, there is always times if I can guarantee that there won ' t is any SQL inserts, D Eletes, or UPDATEs occurring, so I find it's really easy-to-perform a MySQL backup using the Mysqldump utility program. Here's how it works.
Create a MySQL backup with mysqldump
I was just working in a Drupal database, and decided that I wanted to make a backup of Drupal ' s MySQL database before I di D something that might screw up the database (converting a wordpressdatabase to a Drupal database). So, I made a backup of my current MySQL Drupal database using the following mysqldump
command:
Mysqldump--opt--user=root--password drupaldb > Drupaldb-20090505.sql
Note that this command, is the drupaldb
name of the My database, not the password. --password
The argument just tells MySQL to prompt me for the password, because I don ' t want to type it right here on the Comman D line. So, immediately after I enter that command, MySQL prompts me for root
the user's password, like this:
Enter Password: _
Once I Enter that password, my drupaldb
database is dumped to a file in the current directory named drupaldb-20090505.sql
.
MySQL backup-a slightly different syntax
Note that you can also enter your mysqldump
command as shown next, which are equivalent to the previous command:
mysqldump--opt-u root-p drupaldb > Drupaldb-20090505.sql
In both of these examples, the 20090505
portion of the filename just indicates today's date, May 5, 2009. (Happy Cinco de Mayo.:)
MySQL backup-the general form of mysqldump
That is one specific example of the mysqldump
command. The general form of the backup command was shown here:
mysqldump--opt-u username-p database-name > Backup-file-name
where
username
Can root
is, if you know root
the password, or it can be is the name of the MySQL user that owns your database.
database-name
is the name of your database, which drupaldb
.
backup-file-name
is the name of the backup file, want to create. This would be a plain text file, the mysqldump
command creates for you.
MySQL Database backup shell script
I just created a new MySQL database backup (dump) shell script to automate MySQL backups. In addition to creating the This shell script, I ' ve added new MySQL command line options is shown in this example. If you need to the use additional mysqldump command line options, see this article for more information.
MySQL backup-how to backup a MySQL database