Getting Stuff Into MySQL

August 14, 2006

Forget clumsy scripts to load SQL files into MySQL. Here’s how it worked for me:

check your php.ini “upload_max_filesize”

$newFile = move_uploaded file ($FILES['yourfile']['tmp_name'], '/var/tmp/yourfile');

$sql = "LOAD DATA INFILE '$newFile'

     INTO TABLE db.table

      FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\r'";

Strangely, MySQL 4.x doesn’t like the “ENCLOSED BY” statement (it works, but will only import the first row)