Home  >  Article  >  Database  >  How to solve the MySQL character set encoding problem

How to solve the MySQL character set encoding problem

王林
王林forward
2023-05-28 19:52:041131browse

Method 1: When creating the database, specify the character set

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.

Method 2: Change 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

How to solve the MySQL character set encoding problem

  • 2. Find two places

How to solve the MySQL character set encoding problem

How to solve the MySQL character set encoding problem

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

How to solve the MySQL character set encoding problem

##Click to enter the service and find MySQL

How to solve the MySQL character set encoding problem

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 again

The 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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete