WHAT'S NEW?
Loading...

[SOLVED] How to import a tab delimited file into MySQL

  1. Create your table:
    mysql> create table foo(id INT, mytext TEXT, sparkle DECIMAL(9,4));
    Query OK, 0 rows affected (0.02 sec)
  2. Create your data file, put this in foo.txt, note tabs delimit the 3 columns
    1   twilight sparkle is best pony!  6.6 
    2   pinkie pie is best pony!    3.3 
    3   derpy hooves is best pony!  1.1 
  3. Then import the file:
    mysqlimport --fields-terminated-by='\t' 
                --columns=id,mytext,sparkle 
                --local -u root -ppassword your_database foo.txt
    yourdatabase.foo: Records: 4  Deleted: 0  Skipped: 0  Warnings: 3
  4. Look in the table.
    mysql> select * from foo;
    +------+-------------------------------+---------+
    | id   | mytext                        | sparkle |
    +------+-------------------------------+---------+
    |    1 | twilight sparkle is best pony |  6.6000 |
    |    2 | pinkie pie is best pony       |  3.3000 |
    |    3 | derpy hooves is best pony     |  1.1000 |
    +------+-------------------------------+---------+
    4 rows in set (0.00 sec)
The rows were loaded.

0 comments:

Post a Comment