Mysql中文乱码

2023年 9月 25日 94.3k 0

一、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:ProgramDataMySQLMySQL Server 5.1data)

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;

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论