本地正常,部署到服务器运行的时后,给数据库插入中文数据时会报错
第一步
首先在 etc/my.cnf修改字符编码为utf8mb4
[root@iZ2zebh41nm7vqxyy35hiqZ jar]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
[mysqld]
init_connect='set collation_connection = utf8mb4_general_ci'
init_connect='set collation_database=utf8mb4_general_ci'
init_connect='set names utf8mb4'
init_connect='set character_set_connection=utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@iZ2zebh41nm7vqxyy35hiqZ jar]#
结果还是报错,有点懵
第二步
更改数据库编码:
ALTER DATABASE 数据库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
更改表编码:
ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
更改列编码:
ALTER TABLE 表面 CHANGE 列名 列名 VARCHAR( 36 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL
因为没多少数据,我直接删除整个表
只更新了数据库编码