Thursday, August 11, 2011

Importing comma separated values in mysql

mysql -uroot -p --execute="USE databasename;LOAD DATA INFILE 'd:/path/sql-file.txt' INTO TABLE table_name FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'; SHOW WARNINGS"

There are a lot of problems which comma separated files make. For example:
- new lines
- commas in field

This is not recommended for migration between different kinds of databases (MySQL <-> Oracle)

Note: mysqlimport is not recommended, because it cannot show the warnings (it is feature request from year 2005, so i suppose will not be implemented)

No comments:

Post a Comment