Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Copy a database from one account to another account by ssh

Discussion in 'Database Discussion' started by pbixdesign, Jan 14, 2018.

  1. pbixdesign

    pbixdesign Registered

    Joined:
    Jan 9, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  2. Eminds

    Eminds Well-Known Member

    Joined:
    Nov 10, 2016
    Messages:
    267
    Likes Received:
    20
    Trophy Points:
    18
    Location:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,813
    Likes Received:
    84
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. pbixdesign

    pbixdesign Registered

    Joined:
    Jan 9, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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.
     
    #4 pbixdesign, Jan 15, 2018
    Last edited by a moderator: Jan 15, 2018
  5. cPWilliamL

    cPWilliamL cP Technical Analyst II
    Staff Member

    Joined:
    May 15, 2017
    Messages:
    257
    Likes Received:
    29
    Trophy Points:
    103
    Location:
    America
    cPanel Access Level:
    Root Administrator
    Certainly, perform this on the destination server:
    Code:
    ssh usr@remote-host 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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice