A
A
Alexander Pashchenko2013-02-06 08:05:44
MySQL
Alexander Pashchenko, 2013-02-06 08:05:44

MySQL dump file and encodings. Need help

Preamble

So. I have a database of one site. It's happening on Windows. MySQL 5.5.
Encodings are always in UTF8.

mysql> show global variables like 'char%';

 character_set_client utf8
 character_set_connection utf8
 character_set_database utf8
 character_set_filesystem binary
 character_set_results utf8
 character_set_server utf8
 character_set_system utf8


The database itself was created with charset=utf8 and collation=utf8_general_ci
All tables in it are the same with charset=utf8 and collation=utf8_general_ci

Act I

Okay. We connect from an ASP script via ADODB (ODBC). I remind you that this is happening in Windows.
Here is the connection line:
Driver={MySQL};Stmt=SET NAMES 'utf8';SERVER=localhost;DATABASE=Mybase;UID=Myuser;PWD=Mypass;


We select records from the table and we see … abracadabra.
Using the method of selecting page encodings in Firefox, we understand that this is CP1251.

Yes, but how?!!!

Act II

Okay. I am doing mysqldump.
I open the dump in Notepad++
I go to the Encoding menu and make sure that the encoding is UTF8. All Russian letters in the dump are read normally.
For reliability, I do Encoding - Convert to UTF8. Russian letters remained Russian.
I upload the processed dump (now it’s definitely in UTF8) into the database.

And nothing. Again abracadabra.

Act III

Okay. Could it be Voldemort's fault? Maybe dark forces are hiding somewhere between Mysql and ASP script?
I connect to the database through the console mysql-client.
I make a selection - the same thing. Abracadabra. Yes, how is it?
Data was uploaded in UTF8, base in UTF8.

Act IV

Damn. I write my script in Notepad++. I strictly follow that the encoding in the editor is UTF8. In it, I add several hardcoded entries to the script in the same table.

I get it back through the console, script, and even through Navicat.
What the hell? My script added data in UTF8. And, those that were uploaded to the database from the dump ended up in CP1251 (I remind you that the dump file contained data in UTF8).

Ace V

O_O WTF?

Help good people to understand where the glitch sat down.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Beresnev, 2013-02-06
@sectus

Nothing is said how the data got into the database. But I see that they were written there in CP1251.

R
rPman, 2013-02-06
@rPman

Console in windows with cp866 encoding, that's why it's 'crazy'... what's in test.txt?
mysql .... -e "select * from table" > test.txt

V
VBKesha, 2013-02-06
@VBKesha

At the beginning of the dump, sometimes it would also be nice to write SET NAMES utf8;

W
Wott, 2013-02-06
@Wott

Judging by act No. 4 in the database in CP1251, although act No. 2 is not compatible with act No. 4, you must have made a mistake somewhere.
Alternatively, convert fields with Russian text to blob and see what happens

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question