Ales
Ales

Reputation: 1

How to fix hex UTF-8 bytes characters (in an latin1_swedish_ci table)

I've got a latin1_swedish_ci databases with UTF-8 bytes characters in it, which are displayed as %C5%A1, %C4%8D,...

I already convert database and tables from latin1 to utf8, but i still need to fix UTF-8 bytes characters.

ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

MySQL default character set:

SHOW VARIABLES LIKE  'char%'

character_set_client    utf8mb4 
character_set_connection    utf8mb4 
character_set_database  utf8mb4 
character_set_filesystem    binary  
character_set_results   utf8mb4 
character_set_server    latin1  
character_set_system    utf8    
character_sets_dir  /usr/share/mysql/charsets/  

I tried MySQL function without success:

convert(cast(convert(name using  latin1) as binary) using utf8)

I really need help here! Thank you.

Upvotes: 0

Views: 338

Answers (1)

Rick James
Rick James

Reputation: 142208

Are you using PHP? Is there a call to urlencode()? Don't. Use that function only for building url strings.

Let's double check what you have in the table. Do SELECT HEX(...) ... -- pisarniška should become (spaces added for clarity):

70697361726E69 C5A1 6B61   if correctly stored as utf8mb4 (or utf8)
70697361726E69 254335 254131 6B61   if urlencoded first

Upvotes: 1

Related Questions