mysql中文乱码

1、mysql配置修改

sudo nano /etc/mysql/my.cnf

 

[mysql]

default-character-set=utf8

[mysqld]

default-character-set=utf8

 

2、创建数据库时

 

CREATE DATABASE sample

       CHARACTER SET utf8

       DEFAULT CHARACTER SET utf8

       COLLATE utf8_general_ci

       DEFAULT COLLATE utf8_general_ci ;

 

3、调整数据库字符集

 

ALTER DATABASE sample CHARACTER SET utf8 

       DEFAULT CHARACTER SET utf8

       COLLATE utf8_general_ci

       DEFAULT COLLATE utf8_general_ci;

 

4、查看字符集

SHOW VARIABLES LIKE '%character%' ;

SHOW VARIABLES LIKE '%collation%' ;

 

 

来源:http://www.leyond.info/mysql-chinese-garbled-summary/

你可能感兴趣的:(mysql)