Overview of the default character set of mysql
First, MySQL character set problem is two concepts:
- haracter Sets
- Collations
The former is a character encoding and content, which are some of the rules of the former compare operation. These two parameters can be set in the number of database instances , a single database , table , column specify the four levels and the like.
For users, it is generally recommended to use utf8 encoding 存储数据
. And to solve the garbage problem, not just the MySQL data 存储
, and also 用户程序文件的编码方式
, the user program and MySQL数据库的连接方式
have a relationship.
Server
Compiler can specify the default character set when you install Mysql - the coding problem strangled in the cradle
MySQL has a default character set, this is the time of installation determined, you can specify the default character set by these two parameters at compile time to utf8 MySQL
in MySQL5.5 version
DEFAULT_CHARSET=utf8
DEFAULT_COLLATION=utf8_general_ci
In mysql5.1 version
--with-charset=utf8
--with-collation=utf8_general_ci
Such a designation, the client connected to the database encoding utf8 also default, the application does not need any processing.
After installing modify the default binary character set - remedial action
Installed with the binaries, so this time the MySQL default character set is latin1
, you can modify the my.cnf file parameters, change the default character set.
First, solve the problem of data storage and comparison, but the client is connected to no effect.
- Add in the [mysqld] under
mysql 5.5 version
character-set-server=utf8
mysql 5.1 version
default-character-set=utf8
- In
[client]
add under
default-character-set=utf8
The default character to build such a database to build the table when the set is utf8
.
Client
The client needs to set these parameters when you log on, but these three parameters can not be written in a configuration file my.cnf, the dynamic can only be modified by the set command
SET character_set_client = utf8
SET character_set_results = utf8
SET character_set_connection = utf8
init_connect command will be executed when the trigger each normal user connected up, may be in [mysqld]
line to set the connection character sets - Part add the following:
In [mysqld]
add under:
init_connect = 'SET NAMES utf8'
But note that this command has super user permissions are not in effect.