Linux下MySQL编码问题

WBOY
发布: 2016-06-07 16:52:42
原创
1326 人浏览过

Linux环境下默认登录mysql之后show variables like

Linux环境下默认登录mysql之后show variables like '%character%', 出现

mysql> show variables like '%character%';

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+


修改/etc/mysql/my.cnf

在[client]下增加default-character-set=utf8
在[mysqld]下增加default-character-set=utf8

同时加上init_connect='SET NAMES utf8' (设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行)

重新启动mysql,执行:sudo /etc/init.d/mysql stop 然后sudo /etc/init.d/mysql start

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/ |
+--------------------------+----------------------------+


即使做了以上修改如果直接数据库再创建表,然后存入中文,取出来的会是问号。解决的办法是:

创建数据库的时候指明默认字符集为utf8,,如:
create database test default character set utf8;

linux

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板