How to view and modify the encoding of the current database in MySQL

Source: Internet
Author: User

How to view and modify the encoding of the current database in MySQL

In MySQL, database encoding is a very important issue. Sometimes we need to check the encoding of the current database, or even modify the database encoding.

The SQL statement for viewing the current database code is:

Mysql> use xxx
Database changed
Mysql> show variables like 'character _ set_database ';
+ ------------------------ + -------- +
| Variable_name | Value |
+ ------------------------ + -------- +
| Character_set_database | latin1 |
+ ------------------------ + -------- +
1 row in set (0.00 sec)

Above, we first switch to the xxx database, and then use the SQL statement: show variables like 'character _ set_database '; to view the encoding of the xxx database. The query result is latin1 encoding.

Next, we will modify the encoding of the xxx database and change it to gb2312.

Mysql> alter database xxx character set gb2312;
Query OK, 1 row affected (0.00 sec)

Mysql> show variables like 'character _ set_database ';
+ ------------------------ + -------- +
| Variable_name | Value |
+ ------------------------ + -------- +
| Character_set_database | gb2312 |
+ ------------------------ + -------- +
1 row in set (0.00 sec)

Two things are also done here:
1. Use the SQL statement: alter database xxx CHARACTER SET gb2312; SET the encoding of the xxx database to gb2312.
2. Use show variables like 'character _ set_database 'again to check the current xxx encoding. After confirmation, the database code has been changed to gb2312.

3. Of course, in many cases, it is changed to UTF-8 encoding.

This article describes how to view and modify the encoding of the current database in MySQL. I hope it will help you. Thank you!

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.