Load an entire file onto a mysql table

Last updated:

Suppose you have a text file with thousands of names, each on a line, like this:

John
Philip
Jane
Paula
Mark

There's a simple way to load all of them onto a MySQL table, but few know about it:

Log into mysql

mysql -u <username> -p

Select the database you want to use:

use mydb;

Then load the file:

LOAD DATA LOCAL INFILE '/home/<name>/textfile' into table persons(name);

(Don't forget the semicolon)

That's it. MySQL will load all the names onto the table, into the field you've specified.

Dialogue & Discussion