How to view and modify the encoding of a MySQL database

Source: Internet
Author: User

The author of the website has been in the database from the virtual space to a separate server, just installed above the database code with my original, the original is latin1, the current is the GBK format, due to different coding, sometimes the site will appear garbled, Here's a brief look at how to view and modify the encoding of the MySQL database:

1. View Database encoding
First look at the currently used database encoding, login database management, run the statement:

Mysql> Use Testsql
Database changed
Mysql> Show variables like ' character_set_database ';
+------------------------+-------+
| variable_name | Value |
+------------------------+-------+
| Character_set_database | Latin1 |
+------------------------+-------+
1 row in Set (0.00 sec)

First switch to the TESTSQL database and then use the SQL statement: Show variables like ' character_set_database '; You can see that the TESTSQL database is latin1 encoded.

2. Modify the database encoding
To modify the code of the database Testsql, modify it to GBK.

mysql> ALTER DATABASE Testsql CHARACTER SET GBK;
Query OK, 1 row Affected (0.00 sec)

Mysql> Show variables like ' character_set_database ';
+------------------------+--------+
| variable_name | Value |
+------------------------+--------+
| Character_set_database | GBK |
+------------------------+--------+
1 row in Set (0.00 sec)

This article is from the "Chinese name Chong + Technology Blog" blog, please be sure to keep this source http://nj63nscom.blog.51cto.com/1050383/1559325

How to view and modify the encoding of a MySQL database

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.