Variable_name | Value |
---|---|
character_set_client | utf8mb4 |
character_set_connection | utf8mb4 |
character_set_database | utf8mb4 |
character_set_filesystem | binary |
character_set_results | utf8mb4 |
character_set_server | utf8mb4 |
character_set_system | utf8 |
collation_connection | utf8mb4_unicode_ci |
collation_database | utf8mb4_unicode_ci |
collation_server | utf8mb4_unicode_ci |
collation_connection 、collation_database 、collation_server是什么没关系。
但必须保证
系统变量 | 描述 |
---|---|
character_set_client | (客户端来源数据使用的字符集) |
character_set_connection | (连接层字符集) |
character_set_database | (当前选中数据库的默认字符集) |
character_set_results | (查询结果字符集) |
character_set_server | (默认的内部操作字符集) |
这几个变量必须是utf8mb4。
5. 数据库连接的配置
数据库连接参数中:
characterEncoding=utf8
会被自动识别为utf8mb4,也可以不加这个参数,会自动检测。
而autoReconnect=true
是必须加上的。
6. 将数据库和已经建好的表也转换成utf8mb4
更改数据库编码:
更改表编码:
如有必要,还可以更改列的编码
7、在第3步设置character_set_database,character_set_server不成功的可以试下直接在mysql.exe下
set @@character_set_server='utf8mb4'; set @@character_set_database='utf8mb4';
这下数据库就可以存下emoji表情的编码了。
附上我的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. [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 # 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 = ..... # datadir = ..... # port = ..... # server_id = ..... # 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相关内容感兴趣的读者可查看本站专题:《MySQL存储过程技巧大全》、《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》及《MySQL数据库锁相关技巧汇总》
希望本文所述对大家MySQL数据库计有所帮助。