Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy mysql database from mysql command line

Tags:

sql

mysql

How do I copy database1 to database2 from the mysql command line?

I know that mysqldump is one option, or I can do

drop table if exists table2; 
create table table2 like table1;
insert into table2 select * from table1;

But, i won't want to do this manually for each table name. Is this possible?

The key here is "from the mysql command line" mysql> ...

like image 493
d-_-b Avatar asked Jul 11 '14 04:07

d-_-b


People also ask

Can I copy MySQL data directory?

Copying the entire data folder If you are copying the entire database installation, so, all of the databases and the contents of every database, you can just shut down mysqld, zip up your entire MySQL data directory, and copy it to the new server's data directory.


1 Answers

First create the duplicate database:

CREATE DATABASE database2;

Make sure the user and permissions are all in place and:

 mysqldump -u admin -p database1| mysql -u backup -pPassword database2; 

You can also refer to the following link for executing this on mysql shell.

http://dev.mysql.com/doc/refman/5.5/en/mysqldump-copying-to-other-server.html

like image 58
abhinsit Avatar answered Oct 01 '22 21:10

abhinsit