MySQL Character set

Source: Internet
Author: User


View MySQL database server and database character set.

mysql> show variables like  '%char% '; +--------------------------+----------------------- --------------+------| variable_name             | Value                                |......+------ --------------------+-------------------------------------+------| character_set_client      | utf8                                 | ......   --  Client Character Set | character_set_connection | utf8                                  |......|  character_set_database   | utf8                                  |......   --  Database Character Set | character_set_filesystem  | binary                               |......|  character_set_results    | utf8                                  |......|  character_set_server     | utf8                                 |......    --  Server Character Set | character_set_system     | utf8                                  |......|  character_sets_dir       | d:\mysql server 5.0\share\ charsets\ |......+--------------------------+-------------------------------------+------



Create a database of different character sets

The default is the Latin character set when you do not change the proofing rules

Create DATABASE Test_utf8 chanacter SET utf8_general_ci; <= UTF8 Character Set database

Create DATABASE TEST_GBK DEFAULT chanacter SET gbk_chinese_ci; <= GBK Character Set database


Cases:

1, according to the development of the program to determine the character set (recommended UTF8)

2. Specify the character set at compile time

-DDEFAULT_CHARSET=UTF8-DDEFAULT_COLLATION=UTF8_GENERAL_CI \

The default character of the table created after that is UTF8

3. Compile without specifying a default character set or a different character set from the program

Specifying characters and creating databases

>create database Test_utf8 chanacter SET utf8_general_ci;  <= UTF8 Character Set database >create db TEST_GBK DEFAULT chanacter set gbk_chinese_ci; <= GBK Character Set database

4, has created a good database has data

Modifying the character set of a database

>alter database test character set utf-8;

5. Modifying character sets through configuration files

# VI/ETC/MY.CNF
[Client]default-character-set=utf8[mysql]default-character-set=utf8[mysqld]character-set-server=utf8

Restart Service

#/etc/rc.d/init.d/mysql Restart



MySQL Character set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.