1. Debian system
(1) Before mysql version 5.5
vim /etc/mysql/my.cnf
Add under [client]
default-character-set=utf8
Add under [mysqld]
default-character-set=utf8
Notice: Note: If you can't start the error report after modification, try to change the default-character-set=utf8 under [mysqld] to character_set_server=utf8 (I have not experimented)
(2) After mysql version 5.5
vim /etc/mysql/my.cnf [client] default-character-set=utf8 [mysqld] default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci
Restart mysql after modification
Note: This method is effective for pro-testing
2. Centos 7 system
Log in to mysql to view the default character set
show variables like '%char%';
Edit the my.cnf file and add default-character-set=utf8 to the file
[client] default-character-set=utf8 [mysqld_safe] default-character-set=utf8 [mysqld] default-character-set=utf8 [mysql] default-character-set=utf8
Restart mysql and log in to the database
show variables like '%char%';
The display is as follows and the modification is successful, and the problem of garbled characters can be solved. Note: The database created after the modification and the imported data must not be garbled, and the database created before is still garbled
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ |