修改mysql的my.ini配置文件保存emoji表情,以及修改后无法启动mysql服务

在测试一个项目中,发布一个内容中包含emoji表情就会报错,原因是mysql没有设置支持utf8mb4,windows下修改mysql的my.ini配置文件,Linux下mysql配置文件是my.cnf

有的mysql配置文件在mysql安装路径下,有的在ProgramDate下的mysql文件夹里


将mysql默认编码改为utf8mb4:

1.关闭mysql(也可以修改配置文件后再重启mysql服务)

2.修改my.ini配置文件

 在[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'

找的方法修改完这些重启mysql就可以使用了,但是我的发现重启mysql失败,于是继续百度,发现了问题:

在mysql配置文件[mysqld] 下有这样一句:

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

将utf8修改成utf8mb4即可重启mysql服务,但个人看到这句话和上面添加的内容重复,觉得可以删除,但是我没有删

3.重启mysql服务

可以通过设置里的本地服务中来重启mysql服务,

 也可以通过cmd进行重启:

 1)、启动:net start mysql57

 2)、关闭:net stop mysql57

4.查看是否设置成功

cmd下登录mysql,然后输入命令:

SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';

到此修改完成,再次测试发现已经可以存emoji表情啦

 

附上修改部分的配置文件代码:

# 
[client]

default-character-set = utf8mb4
# pipe=
# socket=0.0
port=3306

[mysql]
no-beep=

default-character-set=utf8mb4


# SERVER SECTION
# ----------------------------------------------------------------------
# 
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this 
# file.=
# 
# server_type=3
[mysqld]

character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking=

# enable-named-pipe=

# shared-memory=

# shared-memory-base-name=MYSQL

# The Pipe the MySQL Server will use
# socket=MYSQL

# The TCP/IP Port the MySQL Server will listen on
port=3306

# Path to installation directory. All paths are usually resolved relative to this.
# basedir="C:/Program Files/MySQL/MySQL Server 5.7/"

# Path to the database root
datadir=C:/ProgramData/MySQL/MySQL Server 5.7/Data

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8mb4

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

如有错误,欢迎指出。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值