Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Create database like?

Tags:

mysql

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 
like image 728
Anton Avatar asked Mar 27 '12 15:03

Anton


People also ask

Can I use like in MySQL?

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.

How do you create a like table?

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.

How can I create a database in MySQL?

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.


2 Answers

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 :)

like image 85
rgenito Avatar answered Oct 13 '22 00:10

rgenito


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.

like image 39
Devart Avatar answered Oct 12 '22 22:10

Devart