show variables like "char%"; you can see the database encoding, some default to Latin; (status; can also be viewed, some are different)
--Add the following under the [mysqld] tag:
default-character-set = utf8
character_set_server = utf8
Note: If something like "default-character-set=GBK" already exists under this tag, just modify it.
--Add a line under the [mysql] tag
default-character-set = utf8
--Add a line under the [mysql.server] tag
default-character-set = utf8
--Add a line under the [mysqld_safe] tag
default-character-set = utf8
--Add a line under the [client] tag
default-character-set = utf8
2. Restart the MySql service
Windows can be operated in the service manager or from the command line:
net stop mysql Enter
net start mysql Enter
The service name may not necessarily be mysql, please set according to your own
Under Linux, use service mysql restart
If the startup fails, please check the configuration file for setting errors
3. View the setting results and
log in to the MySql command line client: open the command line
mysql –uroot –p Enter
enter password
After entering mysql, execute: show variables like "% character %"; the
display result should be similar to the following:
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
If the encoding is still not utf8, please check the configuration file, or use the mysql command to set:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
At this time, Chinese can be inserted and displayed normally, but the Chinese I imported from the text into the database is still garbled. load data local infile "~/Downloads/data3/4tes.txt" into table book lines terminated by 'EOF' (name,author,type,time,comment,content);
There is a solution on the Internet: first set names utf8; Then import: load data local infile "~/Downloads/data3/4tes.txt" into table book character set utf8 lines terminated by 'EOF' (name,author,type,time,comment,content); that's it. Unconsciously.