分享golang123配置支持emoji🙂

发布于18天前 作者shen100 76次浏览

配置MySQL支持utf8mb4

打开my.conf文件,按照如下的配置就可以支持utf8mb4的字符集了。(注意: MySQL的版本要5.5.3以上)

[client]
default-character-set = utf8mb4

[mysqld]
collation-server = utf8mb4_general_ci
character-set-server = utf8mb4

在修改完my.conf配置之后,重启mysql,检查字符集是否已经更改,除了character_set_filesystemcharacter_set_system外,其他的字符集都变成utf8mb4类型。

mysql> show variables like 'char%';
+----------------------------------+------------------------------------+
| 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                              |
| character_sets_dir          | /usr/share/mysql/charsets/ |
+-----------------------------------+------------------------------------+

配置gorm支持utf8mb4

打开golang123/config.json文件,在database字段中的配置找到Charset, 改为utf8mb4

{
	"database": {
		"Dialect"            : "mysql",
		"Database"        : "golang123",
		"User"	             : "",
		"Password"        : "",
		"Charset"           : "utf8mb4",
		"Host"               : "127.0.0.1",/*数据库ip*/
		"Port"                : 3306,       /*数据库端口*/
		"MaxIdleConns"   : 5,           /*空闲时最大的连接数*/
		"MaxOpenConns" : 10          /*最大的连接数*/
	}
	...
}
收藏
分享
暂无回复