我的解决方案是这样的,将etc/my.cnf中的charset修改为utf8mb4格式
这其中会有点问题,
client的如果写入character-set-server=utf8mb4会报出mysql: unknown variable 'character-set-server=utf8',将其修改为default-character-set=utf8mb4
而mysqld中如果设置为default-character-set=utf8mb4则会在重启时卡死,所以更换为character-set-server=utf8
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
#
# 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
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8mb4
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8
此时进行重启mysql
一、启动方式
1、使用 service 启动:service mysqld start
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start
3、使用 safe_mysqld 启动:safe_mysqld&
二、停止
1、使用 service 启动:service mysqld stop
2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop
3、 mysqladmin shutdown
三、重启
1、 使用 service 启动:service mysqld restart
然后修改表的编码格式
ALTER TABLE table_name CHARSET=utf8mb4;
修改列的格式,将table_name换成表明,column_name换成列名,text换成你原本的格式
ALTER TABLE table_name MODIFY column_name text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
完成.现在可以插入了