Duplicate MySQL database through SSH

Let's say that I have database1and database2.

database1 - contains data

database2 - empty.


I want to copy all the data from database1to database2via SSH - duplicate database1.

Which command should I use?


I 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
+5
source share
3 answers

This will copy the database from S1 to S2

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

Unzip the file

gunzip /tmp/yourfile.sql.gz

Then you will need to import to S2

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

to use

+4
source

Duplicate your MySQL database through SSH with just one command:

mysqldump -u <local-user> -p <local-db> | gzip | ssh user@hostname \
  "gunzip | mysql -u <remote-user> -p<password> <remote-db>"

Please note that you must first create a remote database.

Additional version:

mysqldump -u <local-user> -p <local-db> | xz | pv -W | ssh user@hostname \
"tee remote-dump.sql.xz | unxz | mysql -u <remote-user> -p<password> <remote-db>"

Extended version:

  • xz/unxz ( , - xz 100% CPU, , , , gzip)

  • , pv

  • tee

, , , . - - , , , .

+3

2 :

mysqldump -u customers -p customers > customers.dump



mysql -u new_customers -p new_customers < customers.dump

( , , cd)

: http://support.tigertech.net/mysql-duplicate

+1

All Articles