Completely solve the encoding problem of the database [Chinese garbled] (2021 latest)

In a development, I found a database installed by a direct fool (interface installation, as long as the next step...installation is complete), a default code of latin1 (latin1 is the alias of ISO-8859-1) will appear, and it will be Use utf-8 encoding, not much to say, go directly to the topic:

Cannot insert Chinese characters:
Insert picture description here

The first step : first check the code of the database installed on the computer

Operate on the graphical interface:

instruction:show variables like '%char%';

If yours is the same as the picture below, then you need to modify it to utf8
Insert picture description here

Operate in cmd

(1) Run cmd.exe as an administrator, and then enter: mysql -u your username -p your password, and finally press Enter. For example, mysql -uroot -p123456, log in according to your own password

(2) Input command: show variables like '%char%';still consistent with the above figure.

(3) Please stop the mysql service, and then modify the my.ini or my-default.ini file in the mysql installation directory. (Generally in the bin directory)

Step 1: Add under the [mysqld] tag: character-set-server=utf8

Step 2: Create a new label [client] in the last line, and add under the label: default-character-set=utf8

(4) Restart the mysql service, repeat the above (1) and (2) operations, you should be able to see the following figure, which proves that the mysql database code has been modified successfully.
Insert picture description here

And when we create the table, we don't need to specify the character encoding, it defaults to utf8;

Solve the coding problem thoroughly.

If the configuration file is modified and restarted, the query is still not modified to utf8, you can use the command to modify

set character_set_server=utf8;
set character_set_database=utf8;
show variables like '%char%';

After the modification is completed, use the command again: show variables like '%char%';query, basically it is already utf8, and the configuration file has been completed.

Haven't resolved yet? ? ?
Please don’t doubt that the configuration file does not work. It may be to rebuild a table and check if the table’s encoding is utf8. If it is not, please don’t panic. If you are a student or a beginner, and there is no valuable data, then you You can directly rebuild a library and recreate the table in the new library. The encoding is utf8. Don't ask why I know? Because mine was to rebuild a library to solve the coding problem.

knock off

Thank you for reading~~~
Looking is just an input way of learning. The important thing is understanding, practice and output. Keep the input and output well~~ Otherwise, the input will not be too much, and the output will soon be forgotten ヽ(*.>Д<)o゜

Guess you like

Origin blog.csdn.net/zhangzhanbin/article/details/112682357
Recommended