1

I've been having problems getting a table to properly display utf8 even though the database itself, the client, the connection, the file that loaded data into the table, etc. were all utf8. Either I've missed something and one of those things doesn't hold true or I'm missing something even bigger here. Nope, it's all good as the later hex tests I did show. Keeping the rest of this for anybody else who stumbles across this since I guess it could help troubleshoot other problems? Dunno.

mysql> show variables like "char%";
+--------------------------+--------------------------+
| Variable_name            | Value                    |
+--------------------------+--------------------------+
| character_set_client     | utf8                     |
| character_set_connection | utf8                     |
| character_set_database   | utf8                     |
| character_set_filesystem | binary                   |
| character_set_results    | utf8                     |
| character_set_server     | latin1                   |
| character_set_system     | utf8                     |
| character_sets_dir       | C:\MySQL\share\charsets\ |
+--------------------------+--------------------------+
8 rows in set (0.00 sec)

Looks good to me. character_set_server is latin1, but I can't seem to change that even with character-set-server=utf8 or character_set_server=utf8 in my.ini under [mysqld]. Could potentially be the problem and if so I'm guessing I might have to change something in windows itself? Turns out there were by default multiple .ini for windows and it didn't necessarily load in my.ini last. Just had to be sure to change it in the right one. The other relative bits in case something else jumps out as wrong:

CREATE TABLE `vocab` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `kanji` varchar(250) DEFAULT NULL,
  `hiragana` varchar(250) DEFAULT NULL,
  `english` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 

I created this table in the database shown above and then I loaded in a csv using the LOAD DATA INFILE command. Does LOAD DATA INFILE convert to another charset during any of its steps or something like that? It does not and the file was 100% fine.

Anyway, here is what I get in the command line:

mysql> select kanji,hiragana,english from vocab where id=2;
+-------+----------+---------+
| kanji | hiragana | english |
+-------+----------+---------+
| 愛    | あい     | love    |
+-------+----------+---------+
1 row in set (0.00 sec)

Yes, these are certainly utf8 characters but not the right ones. Still, I re-checked again for sanity and the csv is in fact utf8.

EDIT: did some further testing

mysql> select hiragana, HEX(hiragana),LENGTH(hiragana),CHAR_LENGTH(hiragana) FR
M vocab where id=2;
+----------+---------------+------------------+-----------------------+
| hiragana | HEX(hiragana) | LENGTH(hiragana) | CHAR_LENGTH(hiragana) |
+----------+---------------+------------------+-----------------------+
| πüéπüä     | E38182E38184  |                6 |                     2 |
+----------+---------------+------------------+-----------------------+
1 row in set (0.04 sec)

And at least the length vs. char_length comparison seems right too, since it's 3:1. And not only that, the hex seems like it should be hiragana too, which leads me to believe that maybe the command line client I'm using is setup wrong for displaying it or something?

Also, tested it in a browser and it displays the character correctly. Not really a necessary step since the hex told enough of the story, but hey.

To summarize:

  1. It's a problem with the display on just the client. But, how might I go about fixing it? Is there a way to fix it or does MySQL Command Line Client 5.5 just not support all character types?
user1489920
  • 25
  • 1
  • 4
  • look at this answer: http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how it describes how to set your console to utf8 (which it isnt by default) – x4rf41 Sep 11 '13 at 08:25
  • 1
    Sadly this isn't a full command line interface. It's just a mysql command line interface so a command like that wouldn't work. I know how to get things working in other consoles, just would probably like to know how to get this particular one working for future reference. – user1489920 Sep 11 '13 at 19:37

0 Answers0