mysql Method of modifying the of database character set and the character encoding of the table

  • 2020-06-15 10:23:43
  • OfStack

mysql converts the character encoding of the table to utf-8


alter table tb_anniversary convert to character set utf8;

Modify the database mysql character encoding to UTF8

Step 1: View the current character encoding method


mysql> show variables like'character%';
+--------------------------+----------------------------+
|Variable_name           |Value                     |
+--------------------------+----------------------------+
|character_set_client    |latin1                    |
| character_set_connection |latin1                    |
| character_set_database   |latin1                    |
| character_set_filesystem |binary                    |
|character_set_results   |latin1                    |
|character_set_server    |latin1                    |
|character_set_system    |utf8                      |
|character_sets_dir      | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

When the character encoding is latin1, the user inserts a record of character type (char) into the data table. When displaying this record, the data of character type may not be displayed normally. Therefore, we modify the character encoding of mysql to UTF8. The operation is as follows:

Step 2: Modify the ES22en. cnf configuration file as follows (/etc/ my. cnf) :


[client]
#password      = your_password
port           = 3306
socket         = /var/lib/mysql/mysql.sock
default-character-set=utf8     # Set the default encoding to UTF8


Related articles: