Reputation: 540
I added this rows to my-default file, restarted server, recreated schema, table and data in the tables, but my cyrillic data still looks like '????'. Now I have a new user and such config, but utf8 still does not work.
[mysqld]
init-connect=SET NAMES utf8
character-set-server=utf8
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8
[mysql]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
[mysqladmin]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
[mysqlcheck]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
[mysqldump]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
[mysqlimport]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
[mysqlshow]
character-sets-dir=/usr/share/mysql/charsets default-character-set=utf8
#end
Upvotes: 1
Views: 980
Reputation: 585
I replaced my.cnf by the default my.cnf, added
CHARACTER SET utf8 COLLATE utf8_general_ci;
for the DB and all tables.
Now it is works fine! Thank you very much!
Upvotes: 1
Reputation: 142208
init-connect=SET NAMES utf8
That command is important. However, when you connect as root
(or other SUPER
user), that command is skipped.
Also, you need to make sure that the bytes in your client are utf8.
And the display is utf8.
If you are using the mysql commandline tool: The command "chcp" controls the "code page". chcp 65001 provides utf8, but it needs a special charset installed, too. To set the font in the console window: Right-click on the title of the window → Properties → Font → pick Lucida Console "
Edit 2
Go into Workbench (which you used for INSERTing the text?) and do SELECT HEX('Ремонтные');
This should give a clue of the character set in Workbench. utf8 will say D0A0D0B5D0BCD0BED0BDD182D0BDD18BD0B5
(note the Dxyy pattern); cp866 will say 90A5ACAEADE2ADEBA5
(note: high bit on). Aha! And latin1 will say 3F3F3F3F3F3F3F3F3F
. Look familiar????? Hint: I am pointing finger at Workbench, or your use of it.
Upvotes: 0
Reputation: 930
This will probably do the trick. You need to perform a small query directly before you do INSERT
or UPDATE
. In my db-class it looks like this, which is to be adapted to your needs. $charset
needs to be "utf8"
$db->query('SET CHARACTER SET "' . $charset . '";');
$result = $db->query($query);
I call the function like this
$result = $ddlab->db->db($sql,'utf8');
Good luck !
Upvotes: 0