1

I have an Excel file (.xlsx format) and I want to import it to my database.

I first saved it in .csv format and I checked spelling because I have some fields with text that is formatted for Romanian language with diacritics and it's OK.

Then I made the table with the column names and imported the table using phpMyAdmin selecting Character set of the file: utf-8 and the format using Format: CSV using LOAD DATA.

It loads fine except I lose all Romanian diacritics and I have a column with text that doesn't import all text, it stops if he finds a Romanian letter ex: (ă,â,î,ș,ț). What formatting should i use? for Romanian language is recommended utf-8. Edit 1: OK, Wilk helped me with the solution and i think it's this:

SET NAMES utf8; 
LOAD DATA INFILE '/home/public_html/db/test_db.csv' INTO 
TABLE test_db FIELDS 
TERMINATED BY ';' 
ENCLOSED BY '"' 
ESCAPED BY '\\' 
LINES TERMINATED BY '\r\n';

But now i have a new error #1045 - Access denied for user 'user'@'localhost' (using password: YES). :)

5
  • The column in the table you made that stores the text has the character set to utf8? Commented Jun 21, 2013 at 7:52
  • 2
    did you tried SET NAMES utf8 before doing the LOAD DATA ? Commented Jun 21, 2013 at 7:54
  • @Stephan yes it's set to store utf8_general_ci Commented Jun 21, 2013 at 7:54
  • @Wilq were should i put that? Commented Jun 21, 2013 at 7:55
  • @tmanolescu you should execute it before load data in the same mysql session Commented Jun 21, 2013 at 7:57

1 Answer 1

3

Try:

SET NAMES utf8

Put it in line before LOAD DATA


Your full SQL should look like:

SET NAMES utf8
LOAD DATA INFILE 'file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'

Remember, that FIELDS TERMINATED BY operator is your field seperator

Sign up to request clarification or add additional context in comments.

3 Comments

I am using import function from phpMyAdmin, what would be the correct slq? Something like this? SET NAMES utf8 LOAD DATA LOCAL INFILE '/home/temp/testdb/test_db.csv' INTO TABLE test_db FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'
ok right now my file is on the server in home/public_html/db so the correct path would be: SET NAMES utf8 LOAD DATA INFILE 'home/public_html/db/file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ??
@Wilq y, forgot to put it sorry :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.