MySql 解决数据库乱码问题。

本文介绍如何在MySQL中配置UTF8MB4字符集以解决表情符号存储问题,并提供了具体的配置步骤及验证方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在你的 F:\Service\Mysql的目录下 有个 my.ini文件
如果是 my-default.ini 就将该文件 复制改名成 my.ini

utf8mb4 只支持 mysql 5.5以上的版本。

utf8mb4 的好处是,保存表情等字段时不会出现 Incorrect string value: ‘\xF0\x9F\x8C\xB8’ 的错误。因为 utf8 是 每个字符3个字节,utf8mb4 每个字符是4个字节

复制下面文件,替换里面内容。

# 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.
[mysqld]
# 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 = D:\Service\Mysql
#datadir = D:\Service\Mysql\data
# port = .....
# server_id = .....

[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 # 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 服务器。

注意如果不重启,不会生效。

测试:
进入:cmd 的 mysql
输入:

 show variables like '%char%';

查看 如果都是 utf8 服务去的 乱码问题就解决了。
mysql> show variables like ‘%char%’;
+————————–+———————————-+
| Variable_name | Value |
+————————–+———————————-+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | C:\Service\mysql\share\charsets\ |
+————————–+———————————-+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值