Mysql converts the character encoding of a table to UTF-8.
Copy codeThe Code is as follows:
Alter table tb_anniversary convert to character set utf8;
Modify mysql character encoding to UTF8
Step 1: view the current character encoding method
Copy codeThe Code is as follows:
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, you insert a character type (char) record to the data table. When this record is displayed, data of the character type may not be displayed normally, therefore, we can change the mysql character encoding to UTF8. The procedure is as follows:
Step 2: Modify the my. cnf configuration file as follows (/etc/my. cnf ):
Copy codeThe Code is as follows:
[Client]
# Password = your_password
Port = 3306
Socket =/var/lib/mysql. sock
Default-character-set = utf8 # set the default encoding to UTF8