Archive for the ‘CSV’ Category

Convert Excel file with unicode characters to MySQL

May 17, 2009

Scenario: It takes you the whole morning to try to get data in an Excel file into MySQL table. You found out there were special characters such as “5┬Ám” inside it.

Solution: Save the file as .txt (Tab delimited or MS-DOS or Machintosh) and make sure it’s encoded in utf-8, etc.


  1. Create table in MySQL db using the sample (with only headers trimming off the content) csv file saved from the .xls file;
  2. Save the .xls as Tab delimited .txt;
  3. Load data into MySQL using the following statement (as produced on Windows for tab delimited, double quote inclosing fields.) See here for details:
  4. LOAD DATA LOCAL INFILE '/STUFF/Projects/_tmp/reference.txt' INTO TABLE reference

  5. Clean up the table: You may need to delete the some rows if the Excel table/sheet headers appear as data rows, etc.


May 17, 2009

This is a nice little online tool that allows you to convert *.dbf or *.csv to MySQL “create table/import” statements.

Adding index for a table

August 3, 2007

In Excel:

Approach #1: In the cell 1 of the index row, type in “1” and cell 2, type in “2”. Select both cells. Excel highlights both cells with bold-stroked box. There is a small handler on the bottom-right corner (Supposed to be a feature called “Auto Fill”?) Hold and drag the handler all the way down to the last cell on the index row. Excel should autofill all the rest of the cells.

Approach #2: In the cell 1 of the index row, type in “1”. In cell 2, type in “=ROW_NUM1+1” (For example, if this is row A, type in “=A1+1”. What this formula does is to increment the value of cell 1 by 1, which equals to 2.) Select cell 2; drag the small handler on the bottom-right to all the way down the last cell.


Approach #3: Create a column which is primary key, data type of int and attribute of AUTO_INCREMENT.

CSV to phpMyAdmin from Mac OSX

April 29, 2006

The CSV (comma delimited) file as shown in Word being exported from Excel (Mac version release 1):

The CVS file

The settings:

The settings in phpMyAdmin

The result showing the actual mysql commands:

The result showing the actual mysql commands