4.7. Database Maintenance

You've created your Vehicle Inventory database, put it in production, set up searching, and the client is now pleased with the outcome. Time to sit back and relax, right?

Not quite. There's another thing you might want to consider, to help minimize the cost of a catastrophic loss of the production databases. What you need are backups.

4.7.1. Creating Backups

Backups in MySQL are very easy to perform, thanks to a great set of client tools that come with the system. To create your backup, you can use the mysqldump utility. The first thing you need to do is exit the MySQL client, if needed, and find yourself at your standard shell prompt:

mysql> exit

Once you're back at a command prompt, it's a simple matter of invoking the mysqldump command-line tool. For most database backups, the following generic format will work:

mysqldump --opt databasename > backupfile.sql

Here you're calling the mysqldump command and telling it to dump the database named databasename into a file called backupfile.sql. Also present is the --opt option, which tells the backup utility to use a set of common options that output a format that can help MySQL restore the file more accurately.

For more mysqldump options, type man mysqldump at your command prompt.

To back up the vehicle inventory database, use the following:

mysqldump --opt VehicleInventory > vi_backup.sql

As with the mysql command-line client, if you need to supply a username and password, make sure you use -u and

Get Professional LAMP: Linux®, Apache, MySQL®, and PHP5 Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.