Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of changing character coding in mysql

Shulou Source: shulou.com Published: 2022-06-01 03:25:08 09月29日 Update

This article will explain in detail the method of changing mysql character coding for you. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Mysql command line modifies character encoding

1. Modify the database character encoding

Mysql > alter database mydb character set utf8

2. Specify the character encoding of the database when creating the database

Mysql > create database mydb character set utf8

3. Check the character encoding of mysql database

Mysql > show variables like 'character%' / / query the character encoding of all attributes of the current mysql database +-+ | Variable_name | Value | +- -+-+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | / usr/share/mysql/charsets/ | +-+-+ |

4. Modify the character encoding of mysql database

To modify the character encoding, you must modify the mysql configuration file my.cnf, and then restart to take effect.

You usually need to modify my.cnf in the following areas:

[client] next, add default-character-set=utf8, or character_set_client=utf8

[mysqld] next, add character_set_server = utf8

Because of the above configuration, mysql defaults to latin1, and if it is only through the command line client, mysql will not work after restart.

The following is the way to modify the client command line, which is not recommended

Mysql > set character_set_client=utf8; mysql > set character_set_connection=utf8; mysql > set character_set_database=utf8; mysql > set character_set_database=utf8; mysql > set character_set_results=utf8; mysql > set character_set_server=utf8; mysql > set character_set_system=utf8; mysql > show variables like 'character%' +-- +-- + | Variable_name | Value | +-- -+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | Utf8 | | character_set_system | utf8 | | character_sets_dir | / usr/share/mysql/charsets/ | +-- +-- + 8 rows in set (0.00 sec) about This is the end of mysql's method of changing character coding. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Characters codes data databases commands methods clients clients more articles configurations good practical functions content places properties files articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Shulou Tech Info MySQL Docker