Copy a database from one account to another account by ssh

pbixdesign

Registered
Jan 9, 2018
3
0
1
Spain/French
cPanel Access Level
Root Administrator
Hi,
I want to copy a database from one account to another account that I have on the same server.
I usually do this when it comes to the same account
mysqldump -u user -p'password 'nameBD | ssh user @ the IP mysql -u user -p'password 'DBcopy.
But I can not find a way to do it between 2 different accounts.
The database is very large is the reason why I use the ssh.
thanks for your help
 

Eminds

Well-Known Member
Nov 10, 2016
319
32
28
India
cPanel Access Level
Root Administrator
if you are looking to use same database for 2 different accounts on the same servers , backup the database first , then from cpanel create a new database for the another website from cpanel and restore the backup to that newely created database.
 

24x7server

Well-Known Member
Apr 17, 2013
1,911
97
78
India
cPanel Access Level
Root Administrator
Twitter
But I can not find a way to do it between 2 different accounts.
Support you want to copy database from one user to another shell, so the question is what shell level access do you have, root access or a user access?

If you have root access, perform the below steps:

1. Login to the server.

2. Create dump of the database using mysqldump command.
# mysqldump -u<username> -p user1DB > user1DB.sql

3. Create a new database under user2.

4. restore the dump you created in step 2 on this user using below command;
# mysql -u<username> -p user2DB < user1DB.sql
 

pbixdesign

Registered
Jan 9, 2018
3
0
1
Spain/French
cPanel Access Level
Root Administrator
Thank you Eminds,
That's the first thing I did, but since the database is too big, I always have errors and i never copy the entire database.
we Can not do with ssh?

Thank you 24x7server, I'm going to try this method.
 
Last edited by a moderator:

cPWilliamL

cP Technical Analyst II
Staff member
May 15, 2017
258
30
103
America
cPanel Access Level
Root Administrator
we Can not do with ssh?
Certainly, perform this on the destination server:
Code:
ssh [email protected] mysqldump -u dbuser -ppasswd db_name|gzip >db_name.sql.gz
If you are accessing the remote host via root, you can skip the '-u dbuser -ppasswd' part. If accessing the remote server via cPanel user, you'll need to use correct username/password for SSH and for the database user. Once completed, use `gunzip db_name.sql.gz' to extract it. Then import it into a database you created via cPanel, as described above.