刚刚下载安装好的MySQL,在使用的时候,如果插入中文信息,可能会显示为?,本人就遇到了这个问题。下面分享给大家如果遇到此类问题,该如何解决
修改配置文件
在我们的安装目录中会有一个*.ini配置文件,名字改为my.ini。
然后修改里面的信息
# These are commonly set, remove the # and set as required.
basedir = D:\download\数据库\Mysql\mysql-5.6.44-winx64
datadir = D:\download\数据库\Mysql\mysql-5.6.44-winx64\data
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# mysql端口
port=3306
# 字符集
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
查看编码格式
将配置文件修改完之后,重启mysql。查看编码方式,是否发生变化
show variables like 'char%';
修改后
修改前
修改已经创建好的数据库和表的编码方式改为utf8
ALTER DATABASE 数据库 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE 数据表 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER DATABASE tb1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; show create database db1;
ALTER TABLE t1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; show create table t1;
show full columns from t1;
最终结果:已经存在的表中的数据依然是问号?,新插入的数据可以显示中文 |