Mysql中文乱码

本文详细介绍了MySQL乱码问题的解决方法,包括修改配置文件、指定数据库和表的字符集等步骤,并提供了常用的查看编码格式的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值