Get the App
SLTechnology News&Howtos  ›  Database  › 

How to change the default character set in mysql

Shulou Source: shulou.com Published: 2022-05-31 21:24:46 10月02日 Update

This article is about how to change the default character set in mysql. I think it is very practical, so I share it with you. I hope you can get something after reading this article.

After starting mysql, log in to mysql as root

$mysql-u root-p

> show variables like 'character%'; # perform encoding display

+-+

| | 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/ |

+-+

At some point, we continue to modify the encoding of the mysql default database to ensure that some migrated programs can be displayed properly. Edit the my.cnf file to modify the encoding, which can be set directly with Mysql Server Instance Config Wizard.

Modify 1 / etc/mysql/my.cnf file of 3 my.cnf under linux

Find the client configuration [client] and add below

The default character set of default-character-set=utf8 is utf8

Add when you find [mysqld]

The default character set of default-character-set=utf8 is utf8

Init_connect='SET NAMES utf8' (set to use utf8 encoding when connecting to mysql so that the database runs for utf8)

After modification, restart mysql and query 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/ |

+-+

The above is how to change the default character set in mysql. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Characters character sets codes data databases files more knowledge articles practical clients clients that is work meetings articles time see knowledge points programs industries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Redmi Shulou Information Microsoft