When Chinese garbled characters appear when we install MySQL, it is usually caused by incorrect character set settings in the database. In this case, we need to adjust MySQL's character set to ensure that Chinese characters can be stored and displayed correctly. The following will introduce how to deal with Chinese garbled characters that appear during MySQL installation, and provide specific code examples.
Before solving the problem of Chinese garbled characters in MySQL, you first need to understand the current character set settings of MySQL. You can view it through the following steps:
SHOW VARIABLES LIKE 'character%';
Run the above SQL statement to view the current character set settings of MySQL, including character_set_database, character_set_server, character_set_client, etc.
If you find that the character set settings of MySQL are incorrect and cause Chinese garbled characters, you need to make corresponding adjustments. The following are specific code examples:
vim /etc/my.cnf
Add or modify the following content in the configuration file:
[client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4'
ALTER DATABASE my_database CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; ALTER TABLE my_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
After modifying the character set settings, remember to restart the MySQL service for the changes to take effect:
systemctl restart mysql
Finally, you can test whether MySQL has correctly processed Chinese characters by inserting and querying Chinese characters:
INSERT INTO my_table (column_name) VALUES ('中文测试'); SELECT * FROM my_table WHERE column_name = '中文测试';
Through the above operations, you should be able to solve the Chinese garbled situation that occurs during MySQL installation and ensure that Chinese characters can be stored and displayed correctly. Hope the above code example helps to solve the problem.
The above is the detailed content of How to deal with Chinese garbled characters that appear during MySQL installation. For more information, please follow other related articles on the PHP Chinese website!