比如类似这样报错:
sqlstate[hy000]: general error: 1366 incorrect string value: 'xf0xa7x92xadxefxbc...' for column 'content' at row 1
请参考一下教程:
问题分析:
在mysql 5.5 之前,utf-8编码只支持1-3个字节,支持bmp这部分的unicode编码区;从mysql 5.5开始,可以支持4个字节utf编码 utf8mb4 ,一个字符能够支持更多的字符集,也能够支持更多表情符号。
utf8mb4兼容utf8,且比utf8能表示更多的字符,是utf8字符集的超集。所以现在一些新的业务,比如iso等,会将mysql数据库的字符集设置为utf8mb4。
j9九游的解决方案:
1、将mysql版本升级为5.7版本
2、到数据库,把数据库字符集修改为:utf8mb4_general_ci
3、将数据表的 content 字段类型设置为:longtext、排序规则设置为:utf8mb4_general_ci
4、继续在mysql数据库的my.cnf中关于字符集的配置修改为下面的配置了:
[client]
default-character-set=utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='set names utf8mb4'
skip-character-set-client-handshake = true
[mysql]
default-character-set = utf8mb4
宝塔中的配置文件路径(宝塔下安装的mysql,my.cnf路径:根目录>etc):
也可以直接在宝塔mysql 的配置文件中修改:
修改后,其内容为:
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8mb4 # 这是我们添加的
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = innodb
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 32m
max_allowed_packet = 100g
table_open_cache = 128
sort_buffer_size = 768k
net_buffer_length = 4k
read_buffer_size = 768k
read_rnd_buffer_size = 256k
myisam_sort_buffer_size = 8m
thread_cache_size = 16
query_cache_size = 16m
tmp_table_size = 32m
sql-mode=no_engine_substitution,strict_trans_tables
explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/www/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""
innodb_data_home_dir = /www/server/data
innodb_data_file_path = ibdata1:10m:autoextend
innodb_log_group_home_dir = /www/server/data
innodb_buffer_pool_size = 128m
innodb_log_file_size = 64m
innodb_log_buffer_size = 16m
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2
character-set-server = utf8mb4 # 这是我们添加的
collation-server = utf8mb4_unicode_ci # 这是我们添加的
init_connect='set names utf8mb4' # 这是我们添加的
skip-character-set-client-handshake = true # 这是我们添加的
[mysqldump]
quick
max_allowed_packet = 500m
[mysql]
no-auto-rehash
default-character-set = utf8mb4 # 这是我们添加的
[myisamchk]
key_buffer_size = 32m
sort_buffer_size = 768k
read_buffer = 2m
write_buffer = 2m
[mysqlhotcopy]
interactive-timeout
5、修改完之后,重载mysql配置,并重启mysql服务,即可存入输入法自带的表情了!