Clone a database (MySQL)

Uit De Vliegende Brigade
(Doorverwezen vanaf Database klonen (MySQL))
Naar navigatie springen Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Usually:

mysqldump db_name_old | mysql db_name_new

When --routines & --force are needed:

mysqldump --routines --force bron_db_naam | mysql doel_db_naam

Details:

  • 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