Tizag.com Webmaster Tutorials - A collection of webmaster tutorials from HTML to PHP.

Thursday, February 5, 2009

Import data from EXCEL to MySQL

  1. Save your Excel data as a csv file (In Excel 2007 using Save As)

  2. Check the saved file using a text editor such as Notepad to see what it actually looks like, i.e. what delimiter was used etc.

  3. Start the MySQL Command Prompt (I'm lazy so I usually do this from the MySQL Query Browser - Tools - MySQL Command Line Client to avoid having to enter username and password etc.)

  4. Enter this command:
    LOAD DATA LOCAL INFILE 'C:\\temp\\yourfile.csv' INTO TABLE database.table FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' (field1, field2);

No comments: