一:
运行环境 ubuntu :14.04
mysql:5.5.47
进入mysql 运行 SHOW VARIABLES LIKE 'character_set_%';查看mysql 的支持的编码格式
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | latin | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
将所有的格式修改成utf8,修改my.cnf(也可能是my.ini)
sudo find / -name my.cnf //查看路径 /etc/mysql/my.cnf sudo gedit /etc/mysql/my.cnf //打开文件
在 [client] [mysql] [mysqld_safe]下面插入 default-character-set = utf8
在[mysqld] 下面插入character-set-server=utf8
然后 点击保存
重启mysql
sudo /etc/init.d/mysql restart
再次查看进入mysql 查看编码格式
mysql > SHOW VARIABLES LIKE 'character%'
+--------------------------+----------------------------+ | 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 | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
这样就 哦可 la
二
如果第一种方法还不性,那就试试这种吧!
1.修改数据库的编码格式
//查看数据库编码: mysql> SHOW CREATE DATABASE db_name;
+-----------+--------------------------------------------------------------------+ | Database | Create Database | +-----------+--------------------------------------------------------------------+ | GoodsInfo | CREATE DATABASE `GoodsInfo` /*!40100 DEFAULT CHARACTER SET utf8 */ | +-----------+--------------------------------------------------------------------+ 1 row in set (0.00 sec)
如果不是utf8那就删数据库了再来一次
建数据库的时候我们可以通过这样的指令实现数据库的字符集设置:
CREATE DATABASE `database` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
2.修改表的编码格式
查看表编码:
mysql> SHOW CREATE TABLE tbl_name;
如果报错:
ERROR 1046 (3D000): No database selected
执行下面的:
mysql> use db_name; mysql> show create table tbl_name;
修改表的编码方式:ALTER TABLE `test` DEFAULT CHARACTER SET utf8;该命令用于将表test的编码方式改为utf8;