修改2017.4.9:
最近在使用MariaDB,遇到了同样的问题:中文乱码。因为mariadb他有好几个ini文件,但是可以根据自己开发需要创建一个my.ini,然后我试着去修改mariadb安装目录下的ini文件,死活不生效。然后我在C盘中搜索my.ini发现有一个。然后我就修改了,然后就可以啦
现在我自学到了SQL语句,发现在没有选择字符集时不能存入中文,然后今天看视屏,发现在自己的默认字符集是latin1,
这是什么鬼,然后自己上网查了,发现当初安装没设置就默认这个字符集,哦忘了我的MySQL是解压版,原因是安装版一直安装不上
然后我就开始百度:怎么样修改默认字符集,终于找到一篇博文,就是下面这篇,其中我提取了有用得精华,当然最下面我也会给出
那篇博文的URL;
首先你要查看自己的默认字符集:
查看语句是:show variables like 'character_set%';
然后修改语句是:SET character_set_server = utf8;
SET character_set_database = utf8;
SET character_set_connection = utf8;我就不一一列出语句,就是后面要修改什么就写什么;
这里只是单次修改,意思就是当你退出后再次进入还是会还原为原来的默认字符集latin1;
下面是设置永久的:
SET GLOBAL character_set_client = utf8;
SET GLOBAL character_set_connection = utf8;
SET GLOBAL character_set_database = utf8;
SET GLOBAL character_set_results = utf8;
SET GLOBAL character_set_server = utf8;
修改前:
修改后:
上面的方法是针对解压版和安装版;本人测试发现在我自己的电脑都不可以,最后我只能修改配置文件,其实修改配置文件并没有那么可怕,开始我是不想去修改配置文件,但是实在没办法,才修改了,发现其实修改配置文件很简单,而且一劳永逸,下面是我的配置文件,注意:我的是解压版的MySQL,安装版就别模仿了;
# 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.
[mysql]
default-character-set=utf8
[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:\mysql-5.6.24-win32
# datadir =D:\mysql-5.6.24-win32\data
# port =3306
# 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
注意:
# basedir =D:\mysql-5.6.24-win32
# datadir =D:\mysql-5.6.24-win32\data
这两处是你们自己MySQL安装的路径,改成自己的;
我觉得数据库还是要选择utf8,因为方便将来迁移,而且不容易乱码吧,但是utf8也有个缺点,就是不能按中文拼音排序,就是校对规则比较麻烦,好了学习去了,时间很紧迫,切莫再任命的时候任性,要不会很惨。。。
这是我看到的那篇关于默认字符集的博文,对我有帮助的呢:http://imysql.cn/taxonomy/term/24