Mysql -- set the MySQL character set to utf8 and mysql -- ubuntuutf8 in Ubuntu
1. mysql configuration file address
/Etc/mysql/my. cnf
2. Add the following code below [mysqld]
[Mysqld]
Init_connect = 'set collation_connection = utf8_unicode_ci'
Init_connect = 'set NAMES utf8'
Character-set-server = utf8
Collation-server = utf8_unicode_ci
Skip-character-set-client-handshake
3. Restart the mysql service.
Sudo service mysql restart
4. Check whether the character set is updated to utf8.
Enter mysql, mysql-u root-p, enter show variables like '% character %' to view the character set
+ -------------------------- + ---------------------------- +
| 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/|
+ -------------------------- + ---------------------------- +
Note: The character_set_database value of the database that has been created before the character set is modified will not change, and Chinese data inserted into the database will still display garbled characters, therefore, it is best to change the character set to utf8 after MySQL is installed. Otherwise, subsequent modifications will be troublesome.