alter database testdb character set utf8
查看mysql支持的编码:
show character set也可以使用如下方法查看编码:
SHOW STATUS mysql -uroot use YOUR DATABASE status ---------------------------------- Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3306 Uptime: 53 sec ---------------------------------- 如果 client 为utf8 , 改为: set char set 'gbk'查看数据库编码:show create database your_db_name
mysql查看数据库编码,打开数据库命令行运行:show variables like 'char%'
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
从以上信息可知数据库的编码为latin1,需要修改为gbk或者是utf8;
其中,character_set_client为客户端编码方式;
character_set_connection为建立连接使用的编码;
character_set_database数据库的编码;
character_set_results结果集的编码;
character_set_server数据库服务器的编码;
只要保证以上四个采用的编码方式一样,就不会出现乱码问题。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)