#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    47
    Rep Power
    11

    Exporting data from mysql


    I dont know if this is a mysql or delphi question

    How can i programmatically export a table from mysql into a csv

    I'm using mysql 4.0.1 and programing in delphi 5
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Depends on where you want the file exported. Say that you want the file exported to the same machine that mysql is running on, MySQL has a SELECT * INTO OUTFILE syntax.
    Code:
    SELECT field1, field2, field3 
    INTO OUTFILE '/tmp/file.txt'
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
    FROM tablename;
    See http://dev.mysql.com/doc/mysql/en/SELECT.html for more.

    If you want the file to be exported into a client machine (and mysql is running on a separate server), then you might want to use Delphi to open a database connection and retrieve the data. Then, you can use regular Delphi file functions (or TStringList or even the ADO components) to write out a CSV file.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo