网站建设知识
修改mysql5.6.24解压缩版(免安装版)默认字符编码。
2025-07-22 10:03  点击:0

【目前官方最新版的MySQL数据库都只提供zip版的安装包。所以网上许多解决数据库默认编码的博客都不能使用了。这次安装数据库,总结出修改MySQL数据库默认编码的方法。】

1.安装数据库,

在官网下载zip版安装板包,解压到C盘根目录下(建议安装在C盘根目录下,不然会出现很多错误)。

配置好MySQL的环境变量后,我们通过 cmd 中的 mysqld -install 去安装相关数据库服务。在通过 net start mysql 去连接数据库。最后在通过 mysql -uroot -p 登录数据库。

输入 show variables like 'char%' 可以查看数据库的默认编码:如图。

可以发现各种编码不协调。

2.解决乱码问题:

找到你安装的MySQL目录,有个 my-default.ini的配置文件。这是MySQL数据库自带的配置文件,我们可以复制一份重名为my.ini。放在同一目录下。

用记事本打开my.ini文件,修改如下。 basedir datadir port 不用设置。不然会无法开启数据库服务。 这里加了4行代码,大家可以仔细对下。

# For advice on how to change settings please see# dev.mysql/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 = .....# datadir = .....# port = .....# server_id = .....character_set_server=utf8# 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 [client]port=3306default-character-set=utf8

3.检查:

依次键入 net stop mysql , net start mysql , 重启数据库服务。然后连接数据库。

键入查询编码的命令后,显示如下。代表我们编码修改成功。

如果还要什么安装问题,大家可以在下方留言。一起商量一下。