3

I'm working on a database that the names was saved in using latin1 character set encoding (latini_swedish_ci collation) but the names were in Persian.

It seems some body changed the table collation to utf8 (utf8_bin) but still the data is like this :

enter image description here

I'm wondering how can I fix this values.

I changed table collation and DB collation but still I have this kind of values. Any help will be appreciate.

Thank's in advance

6
  • You will need utf8_general_ci. It is like Arabic. and make sure that the database, the table and the field have the same collation. Commented Apr 17, 2015 at 22:46
  • What is the scripting language that you use in your application? Commented Apr 17, 2015 at 22:47
  • All the types have the same collation. I think this data was maded using phpNuke... I'm trying to write a search engine that will be work independently... Commented Apr 17, 2015 at 22:55
  • Will your search engine application base on PHP too? Commented Apr 17, 2015 at 22:56
  • Could you maybe add a name for us with the characters - it's really hard to try different things with the names only in the image. Commented Apr 17, 2015 at 22:58

2 Answers 2

5

It looks like you had

  • utf8-encoded bytes in the client, and
  • SET NAMES latin1 (or equivalent), and
  • CHARACTER SET latin1 on the target column.

The "fix" to clean up the table is to do the 2-step ALTER described here, which involves

ALTER TABLE Tbl MODIFY COLUMN col VARBINARY(...) ...;
ALTER TABLE Tbl MODIFY COLUMN col VARCHAR(...) ... CHARACTER SET utf8 ...;

where the lengths are big enough and the other "..." have whatever else (NOT NULL, etc) was already on the column.

Sorry, but it will take a long time do fix 1500000 rows.

I am pretty sure this will not work:

ALTER TABLE tbl CONVERT TO CHARACTER SET utf8;  -- no

It would work only if the table currently contains the latin1 (etc) equivalent of the utf8 characters. There is no latin1 equivalent for Arabic characters.

(I see it as Arabic: باسلام --> باسلام)

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

3 Comments

+1 was looking for a good description + example which should do the trick - another +1 for the hit that this will working for all character with latin1 equivalent.
@Rick James Thanks for your time. I followed your steps but still the data is like before. Am I doing something wrong?
Let's verify something else. Please provide SELECT col, HEX(col) ... for some small amount of text in the table. And, if possible, tell me what it should look like. (If you have "double encoding", the cure is even worse.)
1

Change to utf8_unicode_ci like (To change the default character set and collation of a table including those of existing columns - convert to - is here the key part)

alter table <some_table> convert to character set utf8 collate utf8_unicode_ci;

The _ci suffix means sorting and comparison happens case insensitive. so that shouldn't be a problem.

UTF-8 is an encoding for the Unicode character set, which should support pretty much every language in the world.

The only difference comes with sorting your results, different letters might come in a different order in other languages (accents, umlauts, etc.). For example comparing a to ä might behave differently in another collation.


Could you maybe add a name for us with the characters - it's really hard to try different things with the names only in the image.

15 Comments

Thanks for your answer. I used your query but the problem still remains...!!! Both table and columns have the same encoding---> utf8_unicode_ci
Could you dump us the table with some rows? - would like to try it directly so i can provide you a real solution.
let me try to... it's a huge database with more than 1500000 record.... I'll try to upload dump file some where..
simply copy & paste the table create statement & 10 - 20 insert statements - should be enough. Maybe the problem is not coming from the mysql part - could you also show us how you add these data?
I do understand that my layout is lame. If the content is mangled, please provide some details.
|

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.