您好,登录后才能下订单哦!
一、查看当前数据库编码
show variables like '%character%';
可以看到默认的character_set_database编码格式,这里能够看到默认的是latin1.
修改某个数据库的编码方式,进入到该数据库下面,如greenpass
修改为gb2312编码方式:
mysql>use greenpass;
mysql>alter database greenpass character set gb2312;
mysql>show variables like 'character_set_database';
修改为utf-8编码方式:
mysql> alter database greenpass character set UTF8;
mysql> flush privileges;
mysql>show variables like 'character_set_database';
二、修改配置文件
-在 [mysqld] 标签下加上以下内容:
default-character-set = utf8
character_set_server = utf8
注意:如果此标签下已经存在“default-character-set=GBK”类似的内容,只需修改即可。
--在 [mysql] 标签下加上一行
default-character-set = utf8
--在 [mysql.server]标签下加上一行
default-character-set = utf8
--在 [mysqld_safe]标签下加上一行
default-character-set = utf8
--在 [client]标签下加上一行
default-character-set = utf8
重启mysql服务即可。
3、数据库编码验证
进入mysql后 执行 :show variables like "% character %";
显示结果应该类似如下:
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
如果仍有编码不是utf8的,请检查配置文件,也可使用mysql命令设置:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
另外:
建立数据库时可以使用以下命令:
create database app_relation character set utf8;
use app_relation;
source app_relation.sql;
修改数据库编码的命令为:
alter database app_relation character set utf8;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。