WebFaction
Community site: login faq

I use putty connect to my VM, select from mysql but display chinese is Garbled. How can I do?

I have set putty utf-8 , mysql utf-8, the webapp utf-8 Can I set Linux utf-8 ? To display chinese ~

asked 20 Jan '11, 01:45

slientsky
1811
accept rate: 0%


Yes, we are able to reproduce this problem as well:

mysql> SELECT post_name FROM wp_posts;
+-----------+
| post_name |
+-----------+
| about     |
| test      |
+-----------+
2 rows in set (0.00 sec)

mysql> UPDATE wp_posts SET post_name="????????????" WHERE post_name LIKE "test";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT post_name FROM wp_posts;
+--------------+
| post_name    |
+--------------+
| about        |
| ???? |
+--------------+
2 rows in set (0.00 sec)

From our experimentation, it seems like running mysql with the "--default-character-set=utf8" flag helps a lot:

mysql --default-character-set=utf8 -u DATABASE_NAME -p

(then "use DATABASE_NAME" after logging in)

Database changed
mysql> SELECT post_name FROM wp_posts;
+-----------+
| post_name |
+-----------+
| about     |
| test      |
+-----------+
2 rows in set (0.00 sec)

mysql> UPDATE wp_posts SET post_name="????" WHERE post_name LIKE "test";
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT post_name FROM wp_posts;
+--------------+
| post_name    |
+--------------+
| about        |
| ????     |
+--------------+
2 rows in set (0.00 sec)

mysql> UPDATE wp_posts SET post_name="test" WHERE post_name LIKE "????";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> SELECT post_name FROM wp_posts;
+--------------+
| post_name    |
+--------------+
| about        |
| ????     |
+--------------+
2 rows in set (0.00 sec)

mysql> UPDATE wp_posts SET post_name="test" WHERE post_name LIKE "????";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT post_name FROM wp_posts;
+-----------+
| post_name |
+-----------+
| about     |
| test      |
+-----------+
2 rows in set (0.00 sec)

You still can't delete characters or else the query will not match, but that seems to be the only limitation at this point. It definitely appears to be usable. Hope that helps!

permanent link

answered 20 Jan '11, 03:15

ryans ♦♦
5.0k93360
accept rate: 43%

edited 20 Jan '11, 04:46

mysql --default-character-set=utf8 -u DATABASE_NAME -p if I don't want to enter "--default-character-set=utf8" every time when I login DB. Can I set default-character-set=utf8 in the mysql properties file?

(20 Jan '11, 04:27) slientsky

I find that Mysql default Coding Set alt text

I hope to change all to utf8! don't need to enter like --default-character-set=utf8 every time.

(20 Jan '11, 04:33) slientsky
1

We can't modify the server-wide configuration for fear of breaking existing applications, even though "utf8" is the best global encoding format.

How about adding this to your ~/.bash_profile file?:

alias mysql="mysql --default-character-set=utf8"

(20 Jan '11, 04:59) ryans ♦♦

Thanks ! ~/.bash_profile add alias mysql="mysql --default-character-set=utf8" then run $source .bash_profile #in effect

(20 Jan '11, 21:31) slientsky
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×168
×13
×3
×1

question asked: 20 Jan '11, 01:45

question was seen: 3,505 times

last updated: 13 Mar '11, 21:45

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM