views:

490

answers:

3

When I make a query from the mysql console and it has accents or any character that needs to be utf-8 encoded, it gets mugged

INSERT INTO users (userName) VALUES ("José Alarcón");
SELECT userName FROM users;
José Alarcón

SET NAMES utF8 changes nothing --default-character-set=utf8 as parameter changes nothing Keep in mind than this is ONLY from the console. If I use phpmyadmin or make any query from a program, there is no problem at all, but an inserted row from the console gets muggled. I'm using putty on windows as client

~$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Clarification: Mi local computer is windows XP, i'm using putty 0.60 as terminal client. The target system where MySQL is running is a Debian linux I can't find any configuration in putty for character encoding...

Update: Stupid PuTTY, having the encoding configuration inside a menu called "translation" WTF?

A: 

Windows can't handle UTF8 in console and system messages (which putty uses). It wants to use your locale codepage. This is a common and known problem, and it's not solvable without rewriting cmd.exe, or using a different command line tool.

Microsoft have never really bothered about encodings outside their own world, which results in weird windows specific codesets.

Maybe you can change the putty encoding somewhere in its options so that it can at least communicate correctly to the mysql cli?

Tor Valamo
Putty is its own command line tool, separate from cmd.exe
Matt
Nice and informative. Would PowerShell be any different?
Cody Caughlan
@Matt - yes, but it still uses the native communication, which only accepts the locale codepage. I slightly edited the post.
Tor Valamo
So, i can't use a terminal client from Windows? there must be a way
The Disintegrator
Like I said, you may be able to configure putty to accept utf8 input. I don't have it so I'm not able to test it.
Tor Valamo
A: 

Your terminal client must be configured using UTF8. Your shell environment on the server must also be configured as UTF8. You can check it out with the following command.

locale

It depends on the distribution (I'm assuming you are using linux) how the system prefers how you fix the locale information if needed. For instance, Debian (and, I guess, Ubuntu) ask you to use the following command to reconfigure the locale settings.

dpkg-reconfigure locales

Notice; I'm not sure if they've changed this, haven't tested it in a while. :-)

You can of course set the locales in the shell each time you log in or in your profile. I recommend that you use the distribution's method to do it (if you need to do it after all :-)).

Kristinn Örn Sigurðsson
He's using windows.
Tor Valamo
Uhhh. He has never said so. He only said he's using putty on Windows as the console client. He never said if he's using MySQL on Windows, Linux, or what ever else.
Kristinn Örn Sigurðsson
And yes, please take that down vote off my answer since it has no right to be there, since after all, I did read the question carefully and he does not state that if he's connecting to a linux server or just connecting to a local MySQL server running on his Windows computer.
Kristinn Örn Sigurðsson
P.S. In the comment above, I meant that PuTTY is a terminal client, not a console client. :-)
Kristinn Örn Sigurðsson
Upvoted, I didn't know about locale. But it's in utf-8 anyway...
The Disintegrator
Thanks for the up vote. :-POn other matters. What character set is PuTTY using? You are able to change it in the properties/preferences window. Unfortunately I don't have this in front of me.@Tor Valamo 's answer was only mentioning if you were using PuTTY as a command prompt for Windows. You are able to use PuTTY as a SSH client with UTF8 encoding. The MySQL results should be displayed correctly if your ssh client (PuTTY) is configured to use UTF8 encoding and your shell environment (server side) is configured as you pasted in your last edit of your question.
Kristinn Örn Sigurðsson
I was thinking that Putty didn't had a encoding configuration (never found it before). It turned out it was in the "translation" option, I always overlooked it, I though it was for running putty in a different language, not a different encoding...
The Disintegrator
+1  A: 

Set PuTTY to interpret received data as UTF8 in Window -> Translation "Character set on received data".

Alex
Ow, found out before your answer. But, It's the correct answer, so you get the accepted answer :-)
The Disintegrator