Default login after MySQL show variables like '%character% ', appeared
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/|
+--------------------------+----------------------------+
1. Find the MySQL configuration file, copy to the ETC directory, the first step is very important
Use the Find command to locate the CNF file. Remember not to look for my.cnf because it does not necessarily exist, but should find *.cnf.
[Root@linuxserver classes] Find/-iname *.cnf-print
/usr/share/doc/mysql-server-4.1.12/my-medium.cnf
/usr/share/doc/mysql-server-4.1.12/my-huge.cnf
/usr/share/doc/mysql-server-4.1.12/my-innodb-heavy-4g.cnf
/usr/share/doc/mysql-server-4.1.12/my-large.cnf
/usr/share/doc/mysql-server-4.1.12/my-small.cnf
/usr/share/texmf/web2c/mktex.cnf
/usr/share/texmf/web2c/texmf.cnf
/usr/share/texmf/web2c/fmtutil.cnf
/usr/share/texmf/tex/jadetex/jadefmtutil.cnf
/usr/share/ssl/openssl.cnf
After you find it, copy one out.
Cp/usr/share/doc/mysql-server-4.1.12/my-large.cnf/etc/my.cnf
2. Open MY.CNF Modify Code
Vi/etc/my.cnf
Increase Default-character-set=utf8 under [client]
Increase the Default-character-set=utf8 under [mysqld]
At the same time, plus init_connect= ' Set NAMES UTF8 ' (set to connect the MySQL database with the UTF8 encoding, so that the MySQL database to run UTF8)
Restart MySQL, execute: sudo/etc/init.d/mysql stop 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 you do the above changes if the direct database to create a table, and then stored in Chinese, will be taken out of the question mark. The solution is:
When you create a database, you indicate that the default character set is UTF8, such as:
Create DATABASE test default character set UTF8;