create database 数据库名 charset 字符集;
The most commonly used character set is utf8. However, utf8 in MySQL is actually incomplete**. The utf8 here cannot represent enoji( Expression). Later, MySQL made another utf8mb4, which is a complete utf8.
This method only sets the character set for the currently created database, but if you want to create many databases, use this method every time It will be a bit troublesome. Therefore, I recommend you to use the second method to solve this problem by changing the MySQL configuration file.
After creating the database When, if you manually specify the encoding method of the database, the specified character set will prevail. If not specified, MySQL will read its own configuration file to determine which character set to specify.
So it is recommended to use this method to solve this problem. The file that needs to be changed is my.ini
This file is not easy to find. I recommend you a tool to find files everything
Let’s talk about how to change the configuration file
1. First find the configuration file through everything, and then right-click to open the path
2. Find two places
means a comment. Here is the MySQL default character set encoding method
Before modifying, save the original configuration file (very important!).
can be created A text file, save the contents of the original configuration file ctrl c ctrl v
Then change these two places to:
default-character-set=utf8 character-set-server=utf8
After the modification is completed, the default encoding of MySQL is utf8. It can also be modified to utfmb4.
After the modification is completed, restart the MySQL server
##Click to enter the service and find MySQL Then right-click to start. If you fail to restart, there is a high probability that the configuration file has been changed incorrectly. At this time, the previously saved configuration file will be used. This requires first changing the original configuration. File overwrites the modified file and then modifies it againThe above is the detailed content of How to solve the MySQL character set encoding problem. For more information, please follow other related articles on the PHP Chinese website!