Search code examples
mysqldatabasebackupdumpdatabase-dump

Take perfect backup with mysqldump


How can I make a perfect backup of mysql database using mysqldump? When I am making a backup, my tables from specified database are only getting backed up. The procedures and functions are not.

Here's the backup command I am using: (Operating system is Windows Vista.)

mysqldump -u username -p db1 > backup.sql

Solution

  • It depends a bit on your version. Before 5.0.13 this is not possible with mysqldump.

    From the mysqldump man page (v 5.1.30)

     --routines, -R
    
          Dump stored routines (functions and procedures) from the dumped
          databases. Use of this option requires the SELECT privilege for the
          mysql.proc table. The output generated by using --routines contains
          CREATE PROCEDURE and CREATE FUNCTION statements to re-create the
          routines. However, these statements do not include attributes such
          as the routine creation and modification timestamps. This means that
          when the routines are reloaded, they will be created with the
          timestamps equal to the reload time.
          ...
    
          This option was added in MySQL 5.0.13. Before that, stored routines
          are not dumped. Routine DEFINER values are not dumped until MySQL
          5.0.20. This means that before 5.0.20, when routines are reloaded,
          they will be created with the definer set to the reloading user. If
          you require routines to be re-created with their original definer,
          dump and load the contents of the mysql.proc table directly as
          described earlier.