Reputation: 4232
Creating a database with mysql command is like this:
create database new_york;
use new_york;
create table authors(id int,name varchar(10),gender varchar(5));
create table articles(id int,title varchar(255),content text);
Above I created a database named new_york
, and it has two tables authors
and articles
.
Now I need another database named los_angeles
,it has the same tables as new_york
,and each table has the same structure.
I can repeat the sentences above to create it.
create database los_angeles;
use los_angeles;
create table authors(id int,name varchar(10),gender varchar(5));
create table articles(id int,title varchar(255),content text);
But can I create it using command cp
of linux? like this:
cd /var/lib/mysql
cp -a new_york los_angeles
Now in /var/lib/mysql
,there is the folder los_angeles
,and there are table files in this folder.
So is that ok to create databases with command cp
if they have the same tables?
Upvotes: 0
Views: 159
Reputation: 803
No you can not create any database using cp command. the easiest way to do that is
1- dump new_york database without data.
mysqldump -u${USERNAME} -p --no-data new_york > new_york.sql
2- create los_angeles, and import new_york database dump.
CREATE DATABASE los_angeles;
use los_angeles;
source new_york.sql;
Hope This helps
Upvotes: 1