Mysql中文乱码

一、Mysql乱码解决办法

(1)修改 my.ini(MySQLServer Instance Configuration文件)为gbk

[client]

port=3306

[mysql]

default-character-set=gbk


# 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.1/"

#Path to the database root
datadir="C:/ProgramData/MySQL/MySQL Server 5.1/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=gbk

(2)修改data目录中相应数据库目录下的db.opt配置文件(C:\ProgramData\MySQL\MySQL Server 5.1\data)

default-character-set=gbk
default-collation=gbk_chinese_ci

(3)在创建数据库时指定字符集
create database yourDB  CHARACTER  SET gbk;

(4)建表的时候

CREATE TABLE `user` (
 `ID` varchar(40) NOT NULL default '',
 `UserID` varchar(40) NOT NULL default '',
 ) ENGINE=InnoDB DEFAULT CHARSET=gbk;

二、常用命令:
1.查看默认的编码格式:
mysql> show variables like "%char%";

 2.查看test数据库的编码格式:
mysql> show create database test;

3.查看test表的编码格式:
mysql> show create table test;

posted on 2012-09-16 22:11  小-强-斋-太  阅读(108)  评论(0编辑  收藏  举报

导航