Getting Stuff Into MySQL
Mon Aug 14, 2006 · 66 words

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)


back · essays · credits ·