Find the answer to your Linux question:
Results 1 to 2 of 2
I have a table "users" with the columns "username", firstname", lastname". I need to insert the data from a text file where each line contain the username, firstname, and lastname ...
  1. #1
    Linux User geese's Avatar
    Join Date
    Jan 2005
    Location
    Florida / Trinidad W.I.
    Posts
    284

    MySQL insert script

    I have a table "users" with the columns "username", firstname", lastname".

    I need to insert the data from a text file where each line contain the username, firstname, and lastname seperated by spaces.

    Does anyone know how to write a script for this?

    Thanks,
    Geese.
    Registered Linux user # 395739
    direplay.com

  2. #2
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    The command below should work for a text file. Change the path to the file, name of file and name of table. When creating the file, I believe there needs to be a tab between each entry, i.e: username (hit tab key) firstname (tab key),etc

    mysql> load data infile '/home/geese/Documents/users.txt' into table users;

    This has worked for me although sometimes its load infile rather than load data infile??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...