User Tag List

Results 1 to 5 of 5

Thread: MySQL witchcraft

  1. #1
    Lynel Majora's Avatar
    Join Date
    Mar 2006
    Age
    32
    Posts
    1,197
    Mentioned
    24 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    4,388
    Level
    20
    vBActivity - Bars
    Lv. Percent
    93.94%

    MySQL witchcraft

    All I want to do. Is just. Import information.

    So I have this table with numbers and shit right? I export it as a text file with | separating all the columns. Then I use magic and sacrifice a goat to edit all the information with the intent of re-importing it back into the table. But I cannot do this for some unfathomable reason. Why do people invent things that are retarded and intuitive?

    So anyways, does anyone have extensive experience with MySQL? I could sure use some help. :I

  2. #2
    Patra Beldaran's Avatar
    Join Date
    Oct 2001
    Age
    42
    Posts
    9,551
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    17,115
    Level
    37
    vBActivity - Bars
    Lv. Percent
    33.67%
    Achievements It's over 9000!
    Instead of the "|" character, separate the values by commas. Save the text file as a ".csv" file.

    Then run the following commands:
    load data local infile 'myFile.csv' into table MyTable fields terminated by ','
    enclosed by '"'
    lines terminated by '\n'
    (colName1, colName2, colName3)

    Source: http://www.tech-recipes.com/rx/2345/...ly_into_mysql/

  3. #3
    Octorok Glenn the Great's Avatar
    Join Date
    Oct 2000
    Location
    Bible Belt, USA
    Posts
    338
    Mentioned
    13 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    2,416
    Level
    16
    vBActivity - Bars
    Lv. Percent
    13.89%
    Seconded, Beldaran's method is how I do it at work.

    Be mindful that Windows is different from everyone else in that it terminates lines with two characters. If this is your case, you'll want to use LINES TERMINATED BY '\r\n' or else you'll inadvertently load the \r character into your database.
    My last tip is that if you need to do some kind of on-the-fly transformation to the data as it is loaded into MySQL, you can use the @ symbol like this:

    LOAD DATA LOCAL INFILE 'myFile.csv' INTO TABLE MyTable
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    LINES TERMINATED BY '\r\n'
    (colName1, colName2, @colName3)
    SET colName3 = TRIM(@colName3)

  4. #4

    Armageddon Task Manager

    ctrl-alt-delete's Avatar
    Join Date
    Jul 2001
    Age
    37
    Posts
    3,319
    Mentioned
    55 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    10,236
    Level
    30
    vBActivity - Bars
    Lv. Percent
    12.11%
    Quote Originally Posted by Glenn the Great View Post
    Seconded, Beldaran's method is how I do it at work.

    Be mindful that Windows is different from everyone else in that it terminates lines with two characters. If this is your case, you'll want to use LINES TERMINATED BY '\r\n' or else you'll inadvertently load the \r character into your database.
    My last tip is that if you need to do some kind of on-the-fly transformation to the data as it is loaded into MySQL, you can use the @ symbol like this:

    LOAD DATA LOCAL INFILE 'myFile.csv' INTO TABLE MyTable
    FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    LINES TERMINATED BY '\r\n'
    (colName1, colName2, @colName3)
    SET colName3 = TRIM(@colName3)
    Remind me where you work?


    <SUCCESSOR> Its Shadowblazer's dark essence invading the forums

  5. #5
    Octorok Glenn the Great's Avatar
    Join Date
    Oct 2000
    Location
    Bible Belt, USA
    Posts
    338
    Mentioned
    13 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    2,416
    Level
    16
    vBActivity - Bars
    Lv. Percent
    13.89%
    It's on my Facebook, I'd rather not make it public information.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social