【今天为了解决这个字符默认编码的问题花费了将近3个小时。由于版本不同,网上给出的修改方式不尽适用于此版本。特将该版本修改字符编码方式记录如下,以供他人参考】
1、
当我们把zip文件格式解压到指定目录后,并且完成基本环境配置后,打开mysql 5.6.24会发现名为【my-default.ini】的文件。我们用记事本打开该文件会发现并没有【default-character-set = xxx】或者【character_set_server=xxx】,怎么回事呢?网上给出的许多方法都是直接修改这句话的xxx为utf8,不急,下面请看第二步:
2、
复制该文件,并且命名为【my.ini】,这样根目录下就有两个.ini文件了,一个是my-default.ini,一个是my.ini 。接下来我们只需修改my.ini里面的内容就行了。请看第三步:
3、
修改【my.ini】,
在[mysqld]下面添加 character_set_server=utf8,注意是【utf8】不是【utf-8】而且后面没有任何标点符号;
在【sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES】这句话后面再添加三行:
[client]
port=3306
default-character-set=utf8
4、
经过以上三步就ok了。保存后重启服务器,登陆后在命令行输入:【show variables like ‘char%‘;】可查看默认字符集如下图所示:
5、
我的【my.ini】代码,红色代码区为修改之处:
# 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:\mysql-5.6.24-winx64
datadir = D:\mysql-5.6.24-winx64\data
port = 3306
# 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]
port=3306
default-character-set=utf8