将msyql字符集改为utf-8,解决中文乱码问题

1、登陆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 | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

可以看到 character_set_databas  latin1 character_set_server lantin1

要使它们都变成utf-8


2、编辑 /etc/mysql/my.cnf

在[client]下添加

default-character-set=utf8

在[mysqld]下添加

collation-server = utf8_unicode_ci

init-connect='SET NAMES utf8;'

character-set-server = utf8

在[mysql]下添加

default-character-set=utf8


3、重启mysql

sudo service mysql restart




你可能感兴趣的:(mysql)