mysql import from text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alex79
    Confirmed User
    • Jun 2002
    • 996

    #1

    mysql import from text file

    i have some text files that i want to import in mysql..
    fields are delimitated by "|"
    first row contain the columns name
    is there any possibility to import them directelly to mysql without creating the tables first? tables must be autocreated from first line in the moment of the import..
    i know there is mysqlimport utility but require that tabels to be already created before the import..
  • Solid Bob
    Confirmed User
    • Apr 2006
    • 1213

    #2
    Why would you possibly need it to autocreate from the first line going in?
    [email protected]

    Comment

    • FlowerKid
      Confirmed User
      • Sep 2005
      • 1045

      #3
      I think you need a little script (PHP, Perl, ...) that reads the text file and creates the SQL commands for adding the tables and insert the content.

      Comment

      • teksonline
        So Fucking Banned
        • Jan 2005
        • 2904

        #4
        Creating the tables can be done with various command line tricks or simple scripts, but the fact is, what is data, if it is not scoped correctly.. ints, text, vars, etc and placed in properly named fields, or in you're explanation "columns"

        Comment

        • squishypimp
          PostMaster General
          • Aug 2006
          • 10781

          #5
          bump for info

          Comment

          • Solid Bob
            Confirmed User
            • Apr 2006
            • 1213

            #6
            Originally posted by squishypimp
            bump for info
            Page 10 already?
            [email protected]

            Comment

            • psili
              Confirmed User
              • Apr 2003
              • 5526

              #7
              Look up "load data infile".... off the top of my head, and not checking syntax, it would look something like:

              mysql>load data in file 'data.txt' into table [table_name] fields terminated by '|' lines terminated by '\n' ignore 1 lines
              Your post count means nothing.

              Comment

              • darksoul
                Confirmed User
                • Apr 2002
                • 4997

                #8
                Originally posted by psili
                Look up "load data infile".... off the top of my head, and not checking syntax, it would look something like:

                mysql>load data in file 'data.txt' into table [table_name] fields terminated by '|' lines terminated by '\n' ignore 1 lines

                good thing you've read the thread first
                1337 5y54|)m1n: 157717888
                BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
                Cambooth

                Comment

                • psili
                  Confirmed User
                  • Apr 2003
                  • 5526

                  #9
                  Originally posted by darksoul
                  good thing you've read the thread first
                  I'm a bad person.

                  Forgot the table create statement.
                  Your post count means nothing.

                  Comment

                  Working...