Home > Database > Mysql Tutorial > Switch to UTF-8 charset in Mysql on Ubuntu 对于Ubuntu的Mysql_MySQL

Switch to UTF-8 charset in Mysql on Ubuntu 对于Ubuntu的Mysql_MySQL

WBOY
Release: 2016-05-31 08:50:00
Original
1344 people have browsed it

Ubuntu

对于Ubuntu的Mysql中, 选择UTF-8编码

当在Ubuntu中安装Mysql时, 默认的编码集可能是latin-1. 既然Ubuntu使用UTF-8作为大多数东西的编码集, 这样(latin-1)做就有点奇怪了. 但实际上很容易设置.

Mysql的配置文件/etc/mysql/my.cnf 有神奇的一行:

 

!includedir /etc/mysql/conf.d/
Copy after login

这就使得它包含的设置都位于 conf.d 的子目录下. 不推荐去直接改变 my.cnf文件, 因为它会导致一些问题, 当在升级 Ubuntu/Mysql 到一个新的版本时.

创建一个新文件:/etc/mysql/conf.d/utf8_charset.cnf 有下面这些内容

Mysql 5.1

[mysqld]default-character-set=utf8[client]default-character-set=utf8
Copy after login
Mysql 5.5
Copy after login
[mysqld]<br style="background-color: inherit;">character-set-server=utf8<br style="background-color: inherit;">collation-server=utf8_general_ci
Copy after login
[client]default-character-set=utf8
Copy after login

重启mysql, 然后你将会拥有UTF-8的编码集:

$ mysql -u root -p -e "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/ |+--------------------------+----------------------------+ 
Copy after login

original url:http://blog.lesc.se/2011/06/switch-to-utf-8-charset-in-mysql-on.html

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