MySQL character encoding settings

Source: Internet
Author: User
Tags mysql command line

1, display the current encoding information

Mysql>show variables like '%character% '

+--------------------------+----------------------------+
| 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/share/mysql/charsets/|
+--------------------------+----------------------------+
8 rows in Set (0.01 sec)

2. Set the client code

Set under [MySQL] or [client] in the/etc/mysql/my.cnf file:
Default-character-set=utf8

Then, exit the MYQL client and reconnect to the MySQL server, which is the setting to take effect. The settings above affect three settings:
Character_set_client
Character_set_connection
Character_set_results

Attention:
The above settings are the same as in command line mode and do not require a restart
Mysql>set names UTF8;

Under Windows command line, execute the following command to solve the Chinese garbled problem
Mysql>set names GBK;

3. Set the server-side encoding

Under [Mysqld] in the/etc/mysql/my.cnf file, set:
Character-set-server=utf8

Restart the MySQL service, which is set to take effect. The settings above affect two settings:
Character_set_database
Character_set_server

4. Modify via MySQL command line

Mysql> set Character_set_client=utf8;
Mysql> set Character_set_connection=utf8;
Mysql> set Character_set_database=utf8;
Mysql> set Character_set_results=utf8;
Mysql> set Character_set_server=utf8;
Mysql> set Character_set_system=utf8;
Mysql> set Collation_connection=utf8;
Mysql> set Collation_database=utf8;
Mysql> set Collation_server=utf8;

MySQL character encoding settings

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.