Need help copying tables between databases

Discussion in 'MySQL' started by Darden12, Nov 2, 2011.

  1. #1
    I'm having a hard time understanding how to copy tables between databases. Even when I avoid all syntax errors, I end up with a "user does not have permission" statement when I run the following.

    include 'connection-info-for-db1.php';
    include 'connection-info-for-db2.php';


    $result=mysql_query("INSERT INTO db1.table_to_be_copied_to (SELECT * FROM db2.table_to_copy_from)");

    When I try to use the Select command to copy between databases (using the same connection info)
    I get "SELECT COMMAND DENIED TO USER" -- although the connection scripts both have permissions set at 777.
     
    Last edited: Nov 2, 2011
    Darden12, Nov 2, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You need to add the user to the db2 database and grant the appropriate permissions. This would normally mean they don't have the permission to select from that database.
     
    jestep, Nov 3, 2011 IP
  3. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks for the reply. I'm new to this stuff, but I think I understand what you're saying, so I'll see if I can do it and then come back here to announce the results!
     
    Darden12, Nov 3, 2011 IP
  4. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    I couldn't find a way to add a second user to a database through my shared hosting provider, so then I researched the problem and found the following statement from my hosting provider:

    Is there any way around this short of upgrading to VPS? I want a way to copy table information between databases, hopefully without having to manually specify the field names within each table.

    Thanks for any further ideas.
     
    Darden12, Nov 3, 2011 IP