Moving data from one MySQL table to another

Discussion in 'MySQL' started by webdzr, Aug 16, 2008.

  1. #1
    I am tring to move user info from a script called noahs classifieds to
    a simple machines forum. Both scripts are on the same database.

    My problem is the query to enter. This is all I have yet and not sure if any
    is right and know some is missing.


    INSERT INTO smf_members (ID_MEMBER, memberName, emailAddress, passwd, dateRegistered, lastLogin )
    SELECT id, name, email, password, creationtime, lastClickTime FROM classifieds_classifiedsuser
    WHERE ??not sure here??


    The fields for the classifieds_classifiedsuser table in order are:

    id, name, email, password, newPassword, rememberPassword, isAdm, affId, creationtime, lastClickTime



    The fields for the smf_members table in order are:

    ID_MEMBER, memberName, dateRegistered, posts, ID_GROUP, lngfile, lastLogin, realName, instantMessages, unreadMessages, buddy_list, pm_ignore_list, messageLabels, passwd, emailAddress, personalText, gender, birthdate, websiteTitle, websiteUrl, location, ICQ, AIM, YIM, MSN, hideEmail, showOnline, timeFormat, signature, timeOffset , avatar, pm_email_notify, karmaBad, karmaGood, usertitle, notifyAnnouncements, notifyOnce, notifySendBody, notifyTypes, memberIP, memberIP2, secretQuestion, secretAnswer, ID_THEME, is_activated, validation_code, ID_MSG_LAST_VISIT, additionalGroups, smileySet , ID_POST_GROUP, totalTimeLoggedIn, passwordSalt

    If anybody can help it would be greatly apreacated as there are over 400 members and entering their info manualy would take forever.
     
    webdzr, Aug 16, 2008 IP
  2. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just leave off "where", you don't need it.

    P.S. make a backup before using such a radical operation!
     
    Sleeping Troll, Aug 16, 2008 IP
    webdzr likes this.
  3. webdzr

    webdzr Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply.

    I try that and I get this error.

    Error
    SQL query:

    INSERT INTO smf_members( ID_MEMBER, memberName, emailAddress, passwd, dateRegistered, lastLogin )
    SELECT id, name, email,
    PASSWORD , creationtime, lastClickTime
    FROM classifieds_classifiedsuser
    MySQL said:

    #1062 - Duplicate entry '16777215' for key 1



    It does add the first row from classifieds_classifiedsuser table to smf_members.
    The ID_MEMBER field is added as 16777215

    But the field id from classifieds_classifiedsuser is 2047436851

    I dont understand what is happening i have deleted that new entry and tried again
    i get the same error each time.

    I even tried omiting the ids altogether like this:

    INSERT INTO smf_members (memberName, emailAddress, passwd, dateRegistered, lastLogin )
    SELECT name, email, password, creationtime, lastClickTime FROM classifieds_classifiedsuser

    I still get same error and first row is added with 16777215 in ID_MEMBER field.

    I just noticed while writing this that in the error that came back (highlighted in red) the password field
    is on a new line and capatalized. Is PASSWORD a sql operator?

    I dont understand because the field is accualy named "password" in table classifieds_classifiedsuser

    Does any of this make any sense?
     
    webdzr, Aug 16, 2008 IP
  4. net-split

    net-split Peon

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if PASSWORD is, try to write [Password] instead, if the Id is a primary key while you transfer the data it probably will not work - you should be better of letting it create it's own id's (PK).
     
    net-split, Aug 18, 2008 IP
    webdzr likes this.
  5. webdzr

    webdzr Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ID is primary key so I left it out and this is error I got.



    INSERT INTO smf_members( memberName, emailAddress, passwd, dateRegistered, lastLogin )
    SELECT name, email, [
    PASSWORD ], creationtime, lastClickTime
    FROM classifieds_classifiedsuser
    MySQL said:

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[password], creationtime, lastClickTime
    FROM classifieds_class



    Thanks net-split it seemed very hopeful

    I even tried without the password just to see what would happen
    got this:

    Error
    SQL query:

    INSERT INTO smf_members( memberName, emailAddress, dateRegistered, lastLogin )
    SELECT name, email, creationtime, lastClickTime
    FROM classifieds_classifiedsuser
    MySQL said:

    #1062 - Duplicate entry '16777215' for key 1


    Back to that Duplicate entry deal.
     
    webdzr, Aug 18, 2008 IP
  6. webdzr

    webdzr Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok figured it out id was primary key my first try messed up the db structure
    had to reinstall left id out and everything worked perfect.

    thanks for help everybody
     
    webdzr, Aug 22, 2008 IP
  7. nirajkum

    nirajkum Active Member

    Messages:
    815
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #7
    ID is auto_increment so do not pass anything to it
     
    nirajkum, Aug 23, 2008 IP