MySQL setting character set character set

Source: Internet
Author: User

This address: http://www.cnblogs.com/yhLinux/p/4036506.html

Set the relevant options in the my.cnf configuration file and change to the corresponding character set.

Set Database Encoding (sudo vi/etc/mysql/my.cnf):

[Client] default -character-set = utf8[mysqld]character-set-server = UTF8collation-server = Utf8_general_ci 

Resources:

  14.1.4 Character Set

5.1.4 Server System Variables

10.5, "Character Set Configuration"

  

10.1 Character Set Support

You can specify character sets at the server, database, table, and column level.

10.1.3 specifying Character sets and collations

10.1.3.1 Server Character Set and Collation

MySQL server has a server character set and a server collation. These can is set at server startup, the command line or in a option file and changed at runtime.

10.1.3.2 Database Character Set and Collation

Every database has a database character set and a database collation.

The character set and collation for the default database can is determined from the values of the character_set_database and collation_database System V Ariables. The server sets these variables whenever the default database changes. If There is no default database, the variables has the same value as the corresponding Server-level system variables, and collation_server .

specify character settings at server startup. To select a character set and collation on server startup, use the --character-set-server and --collation-server options. For example, to specify the options in an option file, include these lines:

[Mysqld]character-set-server=utf8collation-server=utf8_general_ci

These settings apply Server-wide and apply as the defaults for databases created by any application, and for tables create D in those databases.

You can force client programs to use specific character set as follows:

[client]default-character-set=charset_name

This is normally unnecessary. However, when character_set_system differs character_set_server by or character_set_client , and you input characters manually (as database object identifiers, column values, or both), these may is displayed incorrectly in output from the client or the output itself could be formatted INCO rrectly. In such cases, starting the MySQL client with --default-character-set=system_character_set -that are, setting the client character set to match the system characte R set-should Fix the problem.

View Settings results

Before you change my.cnf:

Mysql>SHOW VARIABLES like '%char%';     +--------------------------+---------------------------------------------------------------+| Variable_name| Value|+--------------------------+---------------------------------------------------------------+| Character_set_client| Utf8|| Character_set_connection| Utf8|| Character_set_database| Latin1|| Character_set_filesystem|Binary|| Character_set_results| Utf8|| Character_set_server| Latin1|| Character_set_system| Utf8| | character_sets_dir | /usr/local/mysql< Span style= "color: #808080;" >-5.6. 21-linux -GLIBC2. 5-x86_64 /share/charsets/ Span style= "color: #808080;" >| +-------------------- ------+---------------------------------------------------------------+ 

After setting, restart the MySQL service ($ sudo services mysql restart):

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/local/mysql< Span style= "color: #808080;" >-5.6. 21-linux -GLIBC2. 5-x86_64 /share/charsets/ Span style= "color: #808080;" >| +-------------------- ------+---------------------------------------------------------------+ 

MySQL setting character set character set

Related Article

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.