Clone a database (MySQL)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen


mysqldump db_name_old | mysql db_name_new

When --routines & --force are needed:

mysqldump --routines --force bron_db_naam | mysql doel_db_naam


  • You can use the export of one database directly as an import for the other database: The name of the source database is not hard-coded in the export file
  • The target database must already exist
  • This example assumes you don't need to provide login credentials - Thanks to .my.cnf
  • The export file is not placed in the file system in the meantime. Useful!
  • The source database will of course continue to exist. If you want to rename a database, you must delete the source database afterwards
  • This doesn't work for large databases - I suspect.

Note: I have the impression that the switch --comments is missing. This way you will lose comments in sprocs. You can also fix this via .my.cnf.

See also