1、通过  SHOW VARIABLES LIKE 'character_set_%'; 查看mysql字符集情况

mysql> show variables like "%char%";
+--------------------------+---------------+
| 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 | latin1 |
| character_set_system | utf8 |
+--------------------------+-------------+

2、日狗的 latin1 是很多语言乱码的主要原因,通过修改my.cnf 的方法,一劳永逸的解决乱码问题,两处修改的地方

不知道 my.cnf 文件在哪里,可以使用  whereis my.cnf 命令查找 

# 修改处1:添加以下2行
[client]
default-character-set=utf8

[mysqld]
#skip-grant-tables
#skip-networking
#
# 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
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 修改处2:添加以下3行
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci


Logo

更多推荐