1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help moving MySQL db from one server to another

Discussion in 'MySQL' started by jawinn, Dec 18, 2006.

  1. #1
    I'm trying to move a db from a shared hosting account to a dedicated server. I exported the DB; but I can't get it to import.

    I am using SSL to run bash. This is the first time I have ever done this. If anyone can tell me what the command line is to import the db I'd appreciate it.

    thx,
     
    jawinn, Dec 18, 2006 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    did you export is as a .sql file? if so then you should be able to just enter something like

    mysql < my_db.sql
     
    frankcow, Dec 18, 2006 IP
  3. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    to import the database in bash you can do this.

    mysql -u USERNAME -pPASSWORD dbname < dumpfile.sql

    where USERNAME is your mysql user, PASSWORD is the mysql password (there should be no space between -p and PASSWORD) dbname is the name of the database you wish to import the new data into (create it first) and dumpfile.sql is the exported sql from the old database.
     
    amnezia, Dec 18, 2006 IP
  4. alemcherry

    alemcherry Guest

    Best Answers:
    0
    #4
    mysql -u user_name -p database_name < sqlfile_name

    it will ask for the password. enter the password, you are done.

    1. Notes you will have to be in same directory as sqlfile or will have to give absolute/relative path instead of just name.
    2. if it says mysql command not understood, give full path to mysql on your system.

    HTH

    BTW, you can use phpMyAdmin also, to import and export.
     
    alemcherry, Dec 18, 2006 IP
  5. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #5
    -p is database name not password.
     
    aaron_nimocks, Dec 18, 2006 IP
  6. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #6
    I tried this and I keep getting this error:

    "Can't create database 'acme1001'; database exists"

    This isn't the name of the new database I created. It is the name of the old one on the old shared host account. Any thoughts?
     
    jawinn, Dec 18, 2006 IP
  7. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #7
    Do what alemcherry posted. That way works.
     
    aaron_nimocks, Dec 18, 2006 IP
  8. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #8
    a really good way of doing this would be through cpanel...

    1. go to cpanel of your existing server
    2. click on back up
    3. click on back up individual databases
    4. back up to your local hard disk
    5. go to cpanel of new server
    6. click on back up
    7. restore database from you hard disk

    easy enough? ;)
     
    daboss, Dec 18, 2006 IP
  9. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #9
    That would only work for small databases though right? Well 50 mb and under.
     
    aaron_nimocks, Dec 18, 2006 IP
  10. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #10
    I tried and it didn't work for me.

    Is the user name for the new db or the db dump file?
     
    jawinn, Dec 18, 2006 IP
  11. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #11
    is there a way to launch cpanel from SSL?
     
    jawinn, Dec 18, 2006 IP
  12. MeetHere

    MeetHere Prominent Member

    Messages:
    15,399
    Likes Received:
    994
    Best Answers:
    0
    Trophy Points:
    330
    #12
    Where to insert this command ? Sorry I dont know about sql
     
    MeetHere, Dec 18, 2006 IP
  13. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #13
    go to your cpanel and open mysql databases

    You have to create the database and associate a username before you can import it. If you havent created one yet then you need to now.

    Then when you run the cmd from shell you use that database and username.
     
    aaron_nimocks, Dec 18, 2006 IP
  14. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #14
    no its not :rolleyes:
     
    amnezia, Dec 18, 2006 IP
  15. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #15
    actually the easiest way is to just use phpmyadmin!
     
    frankcow, Dec 18, 2006 IP
  16. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #16
    ok try without specifiying a database

    in other words

    mysql -u USERNAME -pPASSWORD < dumpfile.sql
     
    amnezia, Dec 18, 2006 IP
  17. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #17

    have you tried uploading a 5Gb file to phpmyadmin before?

    phpmyadmin is okay for little databases but its not too good if you have a decent sized one.
     
    amnezia, Dec 18, 2006 IP
  18. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #18

    I have tried this over and over. I created a DB. I created an account. This is what I get each time.


    New DB name = database
    DB user = dbuser
    password = password
    DB to import = olddb.sql

    What I enter in through SSL
    ]# mysql -u dbuser -p database < olddb.sql
    enter password: password
    ERROR 1007 (HY000) at line 12: Can't create database 'database'; database exists

    Any thoughts? It looks like something in the import command wants to create the database, which I already did.
     
    jawinn, Dec 18, 2006 IP
  19. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #19
    If you want to trust me with your ssh cpanel details I can install it, or try.
     
    aaron_nimocks, Dec 18, 2006 IP
  20. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #20
    Ok, from the top, open up your backup file, near the top, theres a section that says create database{} delete that whole section, untill the first command says create table.

    Login to ssh on your server, and type :

    mysql -u username -p

    [enter password, then press enter]

    then do :

    create database the_database;

    then do :

    use the_database;

    then do :

    source /home/me/www/backup.sql;

    where /home/me/www/backup.sql is the location of your edited backup, your database is now imported, type exit......

    The reason I choose to login to the server and have it create the database is not all server admin setup thier mysql server to use the same charset, and that can cause problems when using data structues from alien machines.....
     
    krakjoe, Dec 18, 2006 IP