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

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    14
    Is it possible to transfer flat file to MySQL database?
    I have some flat file like this:
    name::lname::address::email::comment
    And I would like to transfer it all to MySQL since file has grown to 8 MB
    Do you now for any script that does all the job?
    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 1999
    Location
    Seattle
    Posts
    133
    Rep Power
    15
    You could use the mysqlimport utility to read in a flat file. Using one of the options to the import utility, you can specify a string that delimits your fields:

    mysqlimport -u user -ppassword --fields-terminated-by='::' dbname flatfile.txt

    Or you could write a quick perl script that dumps your flatfile into INSERT statements, then feed that file into the mysql utility with the stdin redirect:

    mysql -u user -ppassword dbname < sqlstuff.txt

    You have to make sure that the database exists in MySQL before you use either of those methods. If you use the INSERT statement file, you could define your database before the INSERT statements.

    Don

    [This message has been edited by donarb (edited June 02, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo