In MySQL I want to clone certain databases. Is there such a thing as a
CREATE DATABASE LIKE <template database here>
command?
I know, there is
CREATE TABLE LIKE
The MySQL LIKE OperatorThe LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
Use CREATE TABLE ... LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table: CREATE TABLE new_tbl LIKE orig_tbl ; The copy is created using the same version of the table storage format as the original table.
Using a GUIOpen the MySQL Workbench as an administrator (Right-click, Run as Admin). Click on File>Create Schema to create the database schema. Enter a name for the schema and click Apply. In the Apply SQL Script to Database window, click Apply to run the SQL command that creates the schema.
If you want to clone a database, my_database
for example, you'll want to run a mysql query and then run a command in the linux terminal:
mysql> CREATE DATABASE my_database_copy;
linux terminal (on the machine with the database):
mysqldump -u username -p my_database | mysql -u username -p my_database_copy
From there you'll likely get 2 "Enter password:" prompts....just input your password, press enter, and wait :)
There is no such command.
But you can create a backup (SQL file) of your database, and then restore all objects in the new database.
Also, you can use GUI tools in dbForge Studio for MySQL (free express edition) - Backup or restore a database. It will help you quickly recreate database and its contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With