First: Set parameters in initialization file (MY.CNF)
The default character set for MySQL database is Latin. So it needs to be set in MY.CNF. Like what:
[Email protected] test]# MORE/ETC/MY.CNF
[Mysqld]
Default-character-set=utf8
Then connect to MySQL and view:
mysql> status
Server Characterset:utf8
Db Characterset:utf8
Client characterset:latin1
Conn. characterset:latin1
The second type: Set the client's character set
When you connect to MySQL, you need to add a parameter, such as:
[Email protected] test]# Mysql-uroot-p–default-character-set=utf8
mysql> status
Server Characterset:utf8
Db Characterset:utf8
Client Characterset:utf8
Conn. Characterset:utf8
The third type: Modify the server's environment variable LANG
[Email protected] test]# export Lang=en_us
And then connect to MySQL, you can input Chinese.
Summarize:
The first two methods are mainly to solve the problem of Chinese garbled, the third method is to solve the method can not input Chinese.
MySQL string modified to UTF8 under Debian (reference: Rainysia's Column)
First, go to MySQL (mysql-uroot-p), view the current database character set (status;)
Second, view the current system version (LSB_RELEASE-A)
MySQL cannot insert Chinese
Third, #vim/etc/mysql/my.cnf. (Before 5.5 system) under "client" add
Default-character-set=utf8
Add Default-character-set=utf8 under "Mysqld"
Notice: note
If you can not start the error after modifying the Default-character-set=utf8 change to Character_set_server=utf8, just add to the mysqld below. The client doesn't need to be added.
Iv. #vim/etc/mysql/my.cnf. (after 5.5 system) the following modifications:
[Client]
Default-character-set=utf8
[Mysqld]
Default-storage-engine=innodb
Character-set-server=utf8
Collation-server=utf8_general_ci
V. Restart MySQL (/etc/init.d/mysql stop/etc/init.d/mysql start)
Six, to succeed, into the MySQL view character set (Mysql>show variables like ' character_set_% ';)
MySQL Chinese character-set