Home > Database > Mysql Tutorial > body text

修改MySQL的编码为UTF8

WBOY
Release: 2016-06-07 16:52:24
Original
1007 people have browsed it

MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[client]下面加入

MySQL的中文编码问题最简单的解决方案是:修改mysql的配置文件/etc/mysql/my.cnf (在CentOS下是/etc/my.cnf),在[client]下面加入如下指令:

default-character-set=utf8

[mysqld]下面加上如下指令:

default-character-set=utf8init_connect='SET NAMES utf8'

注意:如果没有[client]段,,就手工加入[client]段。然后重新启动MySQL即可。验证一下是否生效:

mysql> show variables like 'char%'
+--------------------------+----------------------------+
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)

mysql>

这样新建立的数据库缺省就是UTF8编码了。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template