This blog documents a bunch of things I learn. Keeping them here helps me dig out things I might forget, but I hope it could also help others.

Thursday 31 December 2009

Turning a text file into a MySQL DB

Here is something I made from a text file that had formatting like this...
line text1 :: line text1 \n
line text2 :: line text2 \n

In 3 steps, I had it as a MySQL DB;

Step 1)
CREATE DATABASE myDatabaseName;

Step 2)
CREATE TABLE myTableName
(
fieldOne VARCHAR(350),
fieldTwo VARCHAR(350)
);

Step 3)
LOAD DATA LOCAL INFILE 'text-file.txt'
INTO TABLE myTableName
FIELDS TERMINATED BY '::'
LINES TERMINATED BY '\n'
(fieldOne, fieldTwo);

No comments: