Show variables like '% character %' After logging on to mysql by default in Linux
Mysql> show variables like '% character % ';
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
Modify/etc/mysql/my. cnf
Add default-character-set = utf8 under [client]
Add default-character-set = utf8 under [mysqld]
Add init_connect = 'set NAMES utf8' (SET utf8 encoding when connecting to the mysql database to run the mysql database utf8)
Restart mysql and run: sudo/etc/init. d/mysql stop and then sudo/etc/init. d/mysql start
Mysql> show variables like '% character % ';
+ -------------------------- + ---------------------------- +
| 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/|
+ -------------------------- + ---------------------------- +
Even if the above changes are made, if the database directly creates a table and then stores the table in Chinese, the question mark is obtained. The solution is:
Specify the default Character Set utf8 when creating a database, for example:
Create database test default character set utf8;