[<<][sql][>>][..]
Tue Aug 6 15:47:28 EDT 2013

Convert arbitrary CSV file to MySQL table

# start mysql as root to create DB.
mysql> CREATE DATABASE tp;
mysql> GRANT ALL PRIVILEGES ON tp.* TO "tom"@"localhost" IDENTIFIED BY "password";
mysql> FLUSH PRIVILEGES;


# start mysql as user
mysql --local-infile -utom -ppassword tp


# Create an SQL file like this:
CREATE TABLE tp (
       brand   TEXT NOT NULL,
       model   TEXT NOT NULL,
       tac     TEXT NOT NULL,
       info    TEXT NOT NULL,
       profile TEXT NOT NULL,
       date    TEXT NOT NULL,
);
LOAD DATA LOCAL INFILE '/home/tom/beep/SIM/tools/tp_db.csv' INTO TABLE tp FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
# And source it



[Reply][About]
[<<][sql][>>][..]