Mysql 5.7 设置默认urf8mb4
首先:
本次环境:
mysql :
[root@iZbp1haimzmpqcmmhnduqiZ mysqld]# mysql -V mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper
使用yum安装:
yum -y install mysql-community-server
查看默认编码:

find / -name my.cnf
拷贝一份默认的配置文件:
sudo cp /etc/my.cnf /etc/my_default.cnf
然后修改配置文件
vim /etc/my.cnf
注意,mysql是 default-character-set=utf8mb4,mysqld是character-set-server=utf8mb4
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [client] #default-character-set=utf8mb4 #character-set-server=utf8mb4 [mysql] default-character-set=utf8mb4 #character-set-server=utf8mb4 [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 # # 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 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock #default-character-set=utf8mb4 character-set-server=utf8mb4 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
命令:慎用!
服务器启动 :
service mysqld start
systemctl start mysqld
服务器停止:
service mysqld stop
systemctl stop mysqld
服务器重启
service mysql restart
查看编码:

相关说明:
关于utf8mb4官方说明:
* mysql的utf8mb4是真正的对应UTF-8编码
10.9.1 utf8mb4字符集(4字节UTF-8 Unicode编码)
该utfmb4字符集有以下特点:
-
支持BMP和补充字符。
-
每个多字节字符最多需要四个字节。
utf8mb4与utf8mb3字符集形成对比 ,后者仅支持BMP字符,每个字符最多使用三个字节:
-
对于BMP字符,
utf8mb4并utf8mb3具有相同的存储特性:相同的代码值,相同的编码,相同的长度。 -
对于补充字符,
utf8mb4需要四个字节来存储它,而utf8mb3根本不能存储字符。将utf8mb3列转换为时utf8mb4,您无需担心转换补充字符,因为没有。
utf8mb4是一个超集 utf8mb3,因此对于诸如以下串联的操作,结果具有字符集 utf8mb4和整理 utf8mb4_col:
SELECT CONCAT(utf8mb3_col, utf8mb4_col);
类似地,该WHERE子句中的以下比较 根据以下排序utf8mb4_col:
SELECT * FROM utf8mb3_tbl, utf8mb4_tbl
WHERE utf8mb3_tbl.utf8mb3_col = utf8mb4_tbl.utf8mb4_col;
有关与多字节字符集相关的数据类型存储的信息,请参阅 字符串类型存储要求。
关于character_set_system官方说明:
10.2.2 UTF-8 for Metadata
Metadata is “the data about the data.” Anything that describes the database—as opposed to being the contents of the database—is metadata. Thus column names, database names, user names, version names, and most of the string results from SHOW are metadata. This is also true of the contents of tables in INFORMATION_SCHEMA because those tables by definition contain information about database objects.
元数据是“关于数据的数据”。任何描述数据库(而不是数据库内容)的内容都是元数据。
踩坑:
在重启的时候使用了 systemctl restart mysqld
结果报错:
[root@iZbp1haimzmpqcmmhnduqiZ ~]# systemctl restart mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

查看日志:
tail -n 200 /var/log/mysqld.log
警告和错误


mysqd和mysql的配置不同,不能使用default-character-set=urf8mb4
* 其实修改完重启mysql即可
win下5.7
path:C:\ProgramData\MySQL\MySQL Server 5.7

my.ini 修改编码配置:
[mysqld] character-set-server=utf8mb4 collation-server=utf8_general_ci [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4
我的电脑-服务

posted on 2019-07-27 11:13 GhostSugar 阅读(1525) 评论(0) 收藏 举报
浙公网安备 33010602011771号