enloz enloz - 2 months ago 15
MySQL Question

Duplicate MySQL database via SSH

Let's say that I have

database1
and
database2
.

database1
- contains data

database2
- is empty.




I want to copy all data from
database1
to
database2
via SSH - duplicate
database1
.

What command should I use?




I have tried

mysqldump -u user -p database1 > database1.sql
Enter password: mysqldump: Got error: 1045: Access denied for user 'user'@'localhost' (using password: NO) when trying to connect

Answer

This will copy database from S1 to S2

mysqldump --opt <database> | gzip -c | ssh user@wherever 'cat > /tmp/yourfile.sql.gz'

Unzip file

gunzip /tmp/yourfile.sql.gz

Next you'll have to import on S2

mysql -h<host> -u<user> -p<password> < /tmp/yourfile.sql

enjoy

Comments