Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing bulk CSV data in UTF-8 into MySQL

I'm trying to import about 10K rows of UTF-8 encoded data into a new MySQL table.

I can do so successfully with LOAD DATA INFILE via MySQL Workbench but it the UTF-8 characters get mangled. I've tested the database otherwise via PHP and it accepts stores UTF-8 charaters fine. The problem seems to be with LOAD DATA INFILE, and I've come across a few threads about this.

Does anyone know a workaround, or possibly another similarly easy method to import CSV data?

Thank you.

RESOLVED:

For others who see this and have the same problem, just add character set as a parameter when running LOAD DATA INFILE. Simpler than I realised :)

like image 759
Tom Avatar asked Jan 25 '10 15:01

Tom


People also ask

How do I import CSV data into MySQL?

In the Format list, select CSV. Changing format-specific options. If the csv file is delimited by a character other than a comma or if there are other specifications to the csv files, we can change it in this portion. Click Go to start importing the csv file and the data will be successfully imported into MySQL.

What is the difference between CSV and CSV UTF-8?

CSV UTF-8 (comma delimited).This format is recommended for files that contain any non-ASCII characters since the classic CSV format destroys them. Besides CSV, there is one more format that may come in extremely handy for communicating with other programs.


1 Answers

According to MySQL documentation for LOAD DATA, you can specify a CHARACTER SET parameter in your statement to provide the input file character set.

Have you tried providing 'utf8' as the input character set?

like image 84
Miguel Ventura Avatar answered Sep 19 '22 23:09

Miguel Ventura