MySQL views and modifies the current database encoding

  • 2020-12-21 18:13:06
  • OfStack

In MySQL, the encoding of the database is a fairly important issue, and sometimes we need to look at the encoding of the current database or even modify the encoding of the database.

The SQL statement to view the current database encoding 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, let's switch to the xxx database and then use SQL statement: show variables like 'character_set_database'; Took a look at the encoding of the xxx database. The query results in an latin1 code.

Next, let's change the encoding of the xxx database 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)

Here, too, two things are done:
1. SQL alter database xxx SET gb2312 Set the encoding of xxx database to gb2312.
2. Use show variables like 'character_set_database' again; To confirm 1 what encoding xxx is currently. After confirmation, the database code has been modified to gb2312.

3. Of course, es91EN-8 code is modified in many cases

So much for this article on MySQL for viewing and modifying the current database encoding. I hope it will be helpful. Thank you!


Related articles: