在C:\Program Files\MySQL\MySQL Server 5.0\my.ini中设置: [mysql] default-character-set=gb2312 # SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this # file. # [mysqld]# The TCP/IP Port the MySQL Server will listen on port=3306 #Path to installation directory. All paths are usually resolved relative to this. basedir="C:/Program Files/MySQL/MySQL Server 5.0/"#Path to the database root datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/"# The default character set that will be used when a new schema or table is # created and no character set is defined default-character-set=utf8# The default storage engine that will be used when create new tables when default-storage-engine=INNODB# Set the SQL mode to strict # sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
[mysql]
default-character-set=gb2312
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.0/"#Path to the database root
datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/"# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB# Set the SQL mode to strict
# sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)mysql> show full columns from t;
+--------------+------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+--------------+------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| id | int(11) | NULL | NO | PRI | NULL | | select,insert,update,references | |
| name | varchar(5) | latin1_swedish_ci | YES | | NULL | | select,insert,update,references | |
| score | int(11) | NULL | YES | | NULL | | select,insert,update,references | |
| mapping_name | varchar(5) | latin1_swedish_ci | YES | | NULL | | select,insert,update,references | |
| flag | tinyint(1) | NULL | YES | | NULL | | select,insert,update,references | |
+--------------+------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
5 rows in set (0.02 sec)
mysql>set names 'gb2312';1. 确保你表中的字段是中文字符集(gb2312 , gbk, utf8 均可 )
2. 确保你联接中使用的字符集与表中的相同。 可以按 tyuiouio 所说的,在my.ini中把整个MySQL的服务的默认字符集设置为 gb2312, 这样以后你创建的表的默认字符集就是gb2312 了,但之前已经输入的表,需要导出现导入以更新字符集设置。这些问题在MySQL的官方文档中已经有详细说明,建议你先花10分钟浏览一篇。
http://dev.mysql.com/doc/refman/5.1/zh/charset.html