关于mysql在linux下面字符修改的问题
2006-09-05 14:45
483 查看
You inserted CJK characters with
Find out: what version do you have? The statement
Find out: what character set is the database column really in? Too frequently, people think that the character set will be the same as the server's set (false), or the set used for display purposes (false). Make sure, by saying
Find out: what is the hexadecimal value?
If you see
Find out: is a literal round trip possible, that is, if you select “literal” (or “_introducer hexadecimal-value”) do you get “literal” as a result? For example, with the Japanese Katakana Letter Pe, which looks like
If the result doesn't look like
Find out: is it the browser or application? Just use mysql (the MySQL client program, which on Windows will be mysql.exe). If mysql displays correctly but your application doesn't, then your problem is probably “Settings”, but consult also the question about “Troubles with Access (or Perl) (or PHP) (etc.)” much later in this FAQ.
To find your settings, the statement you need here is
+--------------------------+----------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.03 sec)
[/code]
The above are typical character-set settings for an international-oriented client (notice the use of
Although Unicode (usually the
If you can't control the server settings, and you have no idea what your underlying computer is about, then try changing to a common character set for the country that you're in (
Once you get the correct setting, you can make it permanent by editing
INSERT, but when you do a
SELECT, they all look like “?”. It usually is a setting in MySQL that doesn't match the settings for the application program or the operating system. These are common troubleshooting steps:
Find out: what version do you have? The statement
SELECT VERSION();will tell you. This FAQ is for MySQL version 5, so some of the answers here will not apply to you if you have version 4.0 or 4.1.
Find out: what character set is the database column really in? Too frequently, people think that the character set will be the same as the server's set (false), or the set used for display purposes (false). Make sure, by saying
SHOW CREATE TABLE tablename, or better yet by saying this:
SELECT character_set_name, collation_name FROM information_schema.columns WHERE table_schema = your_database_name AND table_name = your_table_name AND column_name = your_column_name;
Find out: what is the hexadecimal value?
SELECT HEX(your_column_name) FROM your_table_name;
If you see
3F, then that really is the encoding for
?, so no wonder you see “?”. Probably this happened because of a problem converting a particular character from your client character set to the target character set.
Find out: is a literal round trip possible, that is, if you select “literal” (or “_introducer hexadecimal-value”) do you get “literal” as a result? For example, with the Japanese Katakana Letter Pe, which looks like
ペ', and which exists in all CJK character sets, and which has the code point value (hexadecimal coding)
0x30da, enter:
SELECT 'ペ' AS `ペ`; /* or SELECT _ucs2 0x30da; */
If the result doesn't look like
ペ, a round trip failed. For bug reports, we might ask people to follow up with
SELECT hex('ペ');. Then we can see whether the client encoding is right.
Find out: is it the browser or application? Just use mysql (the MySQL client program, which on Windows will be mysql.exe). If mysql displays correctly but your application doesn't, then your problem is probably “Settings”, but consult also the question about “Troubles with Access (or Perl) (or PHP) (etc.)” much later in this FAQ.
To find your settings, the statement you need here is
SHOW VARIABLES. For example:
mysql> [code]SHOW VARIABLES LIKE 'char%';
+--------------------------+----------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.03 sec)
[/code]
The above are typical character-set settings for an international-oriented client (notice the use of
utf8Unicode) connected to a server in the West (
latin1is a West Europe character set and a default for MySQL).
Although Unicode (usually the
utf8variant on Unix, usually the
ucs2variant on Windows) is better than “latin”, it's often not what your operating system utilities support best. Many Windows users find that a Microsoft character set, such as
cp932for Japanese Windows, is what's suitable.
If you can't control the server settings, and you have no idea what your underlying computer is about, then try changing to a common character set for the country that you're in (
euckr= Korea,
gb2312or
gbk= People's Republic of China,
big5= other China,
sjisor
ujisor
cp932or
eucjpms= Japan,
ucs2or
utf8= anywhere). Usually it is only necessary to change the client and connection and results settings, and there is a simple statement which changes all three at once, namely
SET NAMES. For example:
SET NAMES 'big5';
Once you get the correct setting, you can make it permanent by editing
my.cnfor
my.ini. For example you might add lines looking like this:
[mysqld] character-set-server=big5 [client] default-character-set=big5
相关文章推荐
- 关于linux下部署 tomcat+mysql 的中文字符问题
- 关于linux环境下修改mysql字符编码的问题
- Linux下MySQL5.6的修改字符集编码为UTF8(解决中文乱码问题,亲测可用)
- 关于Linux下Mysql的编码问题
- 关于linux服务配置的问题 starting MySQL.Manager of pid-file quit without updating fi[failed]
- 关于PHP内部编码与mysql字符差异问题的研究
- Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
- Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
- Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)
- Linux下MySQL的修改字符集编码为UTF8(解决中文乱码问题)
- linux下关于mysql安装的一些问题
- Linux下MySQL5.6的修改字符集编码为UTF8(解决中文乱码问题,亲测可用!)
- 关于mysql的一些时间格式和字符的问题
- 有关于mysql 在linux下去分表名大小写的问题
- linux中修改mysql的默认编码(character_set_server)解决插入乱码问题
- (原创)Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)
- Linux系统下修改MySQL字符编码问题
- 关于在linux上安装mysql的问题
- Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
- 关于Linux和Windows下部署mysql.data.dll的注册问题