在你的 F:\Service\Mysql的目录下 有个 my.ini文件
如果是 my-default.ini 就将该文件 复制改名成 my.ini
utf8mb4 只支持 mysql 5.5以上的版本。
utf8mb4 的好处是,保存表情等字段时不会出现 Incorrect string value: ‘\xF0\x9F\x8C\xB8’ 的错误。因为 utf8 是 每个字符3个字节,utf8mb4 每个字符是4个字节
复制下面文件,替换里面内容。
# 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:\Service\Mysql
#datadir = D:\Service\Mysql\data
# port = .....
# server_id = .....
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
# 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 服务器。
注意如果不重启,不会生效。
测试:
进入:cmd 的 mysql
输入:
show variables like '%char%';
查看 如果都是 utf8 服务去的 乱码问题就解决了。
mysql> show variables like ‘%char%’;
+————————–+———————————-+
| Variable_name | Value |
+————————–+———————————-+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | C:\Service\mysql\share\charsets\ |
+————————–+———————————-+