Linux中MySQL中文乱码

安装MySQL后,启动项目测试发现修改的中文都变成了?

进入数据库查看数据字符编码:

mysql> show variables like 'character%';
+--------------------------+----------------------------------------------+
| Variable_name            | Value                                        |
+--------------------------+----------------------------------------------+
| character_set_client     | utf8                                         |
| character_set_connection | utf8                                         |
| character_set_database   | latin1                                       |
| character_set_filesystem | binary                                       |
| character_set_results    | utf8                                         |
| character_set_server     | latin1                                       |
| character_set_system     | utf8                                         |
| character_sets_dir       | /alidata/server/mysql-5.5.37/share/charsets/ |
+--------------------------+----------------------------------------------+

其中 “ latin1  ” 就是影响中文乱码;

解决方法:找到MySQL安装文件的 my.cnf 文件;如果在Linux中找不到此文件 可以用 命令:whereis my.cnf

找到后进入文件,修改[mysqld]在最后添加 character_set_server=utf8  修改好以后,重启MySQL服务就好,

[mysqld]
port  = 3306
socket=/tmp/mysql.sock
skip-external-locking
log-error=/alidata/log/mysql/error.log
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
lower_case_table_names=1
character_set_server=utf8

这里多说一句 lower_case_table_names=1  就是不区分表名大小写  =0为区分大小写

你可能感兴趣的:(sql,MySQL,linux)