MySql 5.6 版本 2016-07 修改配置文件解决中文乱码问题

来源:互联网 发布:我没有说话 知乎 编辑:程序博客网 时间:2024/06/10 14:47

网上许多方法已经过时了。浪费了我好多时间。

详见官网: mysql 5.6
其中一段是这样描述的:
The my-default.cnf template replaces the older sample option files formerly supplied with MySQL distributions (my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf). As of MySQL 5.6.8, these older files are no longer distributed.

讲的很清楚了。

首先

_进入/usr/share/mysql/目录下,将 my-default.cnf 文件 拷贝至 /etc/mysql/ 目录下_

 cp /usr/share/mysql/my-default.cnf /etc/mysql/

然后将my-default.cnf的内容复制到 my.cnf 中

你可以像下面这样做

cat my-default.cnf >> my.cnf

最后编辑设置my.cnf

在[mysqld] 后面添加 (默认的只有这一个,你可以自己添加)
character-set-server=utf8

[mysqld]character-set-server=utf8# 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 = 3306# server_id = .....# socket = .....# 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> SHOW VARIABLES LIKE 'character%';+--------------------------+----------------------------+| Variable_name            | Value                      |+--------------------------+----------------------------+| character_set_client     | utf8                       || character_set_connection | utf8                       || character_set_database   | utf8                       || character_set_filesystem | binary                     || character_set_results    | utf8                       || character_set_server     | utf8                       || character_set_system     | utf8                       || character_sets_dir       | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rows in set (0.00 sec)mysql> 
0 0
原创粉丝点击