mysql> status; -------------- mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 20378404 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.0.45 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 119 days 10 hours 19 min 1 sec
mysql> status; -------------- mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 20380340 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.0.45 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 119 days 10 hours 35 min 49 sec
Threads: 2 Questions: 384136644 Slow queries: 0 Opens: 2953019 Flush tables: 1 Open tables: 64 Queries per second avg: 37.223 --------------
mysql> select * from cework.english; +--------------+-------------+----------------------------------------------------------+ | word | chinese | note | +--------------+-------------+----------------------------------------------------------+ | relationship | ????? | relationship database | | enterprise | ?? | enterprise edition / standard edition / personal edition | | migration | ?? | migraine(???) | | integrate | ??????? | integrated circuit(????) | | restrict | ????? | he feels this new law will restrict his freedom. | | query | ???????? | question | | structure | ????? | SQL?Structured Query Language | | distinct | ??????????? | select distinct job from scott.emp; | | disaster | ??,???? | dis-???aster?????????????????????????? | | dedicated | ???? | dedicated | +--------------+-------------+----------------------------------------------------------+ 10 rows in set (0.00 sec)
可以发现所查结果中的中文字符显示为乱码,因为Client Conn.所用字符编码为Latin1。
下面在连接服务器时,指定连接字符编码为:gb2312。
[root@cactiez ~]# mysql --default-character-set=gb2312 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20380975 Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> status; -------------- mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 20380975 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.0.45 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: gb2312 Conn. characterset: gb2312 UNIX socket: /var/lib/mysql/mysql.sock Uptime: 119 days 10 hours 41 min 33 sec
Threads: 2 Questions: 384148644 Slow queries: 0 Opens: 2953107 Flush tables: 1 Open tables: 64 Queries per second avg: 37.223 --------------
mysql> select * from cework.english; +--------------+------------------------+-------------------------------------------------------------------------+ | word | chinese | note | +--------------+------------------------+-------------------------------------------------------------------------+ | relationship | 关系,联系 | relationship database | | enterprise | 企业 | enterprise edition / standard edition / personal edition | | migration | 迁移 | migraine(偏头痛) | | integrate | 使结合成为整体 | integrated circuit(集成电路) | | restrict | 限制,约束 | he feels this new law will restrict his freedom. | | query | 疑问,怀疑,查询 | question | | structure | 结构,构造 | SQL:Structured Query Language | | distinct | 截然不同的,完全分开的 | select distinct job from scott.emp; | | disaster | 灾难,彻底失败 | dis-离开+aster星,原是注定命运的星宿已离开,人就要遭不幸即“灾难”来临 | | dedicated | 专注的, | dedicated | +--------------+------------------------+-------------------------------------------------------------------------+ 10 rows in set (0.00 sec)