1.查看MySQL默认字符集
在命令行使用命令 show variables like 'char%';
这里我是在客户端打开mysql命令行的,直接使用windows命令行登录mysql数据库执行上面的命令是一样的效果。
2.文件修改
复制my-default.ini文件,重命名为my.ini;
这样根目录下就有两个.ini文件了,一个是my-default.ini,一个是my.ini。接下来我们只需修改my.ini里面的内容就行了;
3.修改my.ini
主要添加下面几项:
basedir = D:\Program Files\mysql-5.6.17-winx64
datadir = D:\Program Files\mysql-5.6.17-winx64\data
character_set_server=utf8
[client]
default-character-set=utf8
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = D:\Program Files\mysql-5.6.17-winx64
datadir = D:\Program Files\mysql-5.6.17-winx64\data
# port = .....
# server_id = .....
character_set_server=utf8
# 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
[client]
default-character-set=utf8
4.验证操作
修改my.ini配置文件后,需要重启MySQL数据库,然后重新在命令行中执行 show variables like 'char%';
命令,检查字符集是否设置成功。
由上图可以看到,character_set_database 和 character_set_server 由原来的 latin1 改为 utf8 了。
到此MySQL数据库字符集修改完成。
参考资料:
https://blog.csdn.net/jnx1142410525/article/details/70859366
https://blog.csdn.net/sdy1985/article/details/51011599