The default character set for Character_set_database and Character_set_server is Latin1
The simplest perfect way to modify MySQL's my.cnf:
Add default-character-set = UTF8 in the [Client] field
Add Character-set-server=utf8 to the [mysqld] field
Vi/etc/my.cnf[client] #password = Your_passworddefault-character-set = utf8[mysqld]# Skip-grant-tablescharacter-set-server = UTF8
Note that you need to restart the database:
Mysql> Show variables like "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 | /alidata/server/mysql-5.5.40/share/charsets/|+--------------------------+------------------------------------- ---------+8 rows in Set (0.00 sec)
However, it still cannot be displayed:
Mysql> INSERT into articles (Id,content) VALUES (15, ' fully prepared '); Query OK, 1 row affected, 1 warning (0.22 sec) mysql> select * from articles;+----+---------+| ID | Content |+----+---------+| 11 | Ha | | | | xi | | | | AI | | | | HO | | | | +----+---------+5 rows in Set (0.00 sec)
Mysql> Show CREATE TABLE articles;+----------+----------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- +| Table | Create Table |+----------+-------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------+| Articles | CREATE TABLE ' articles ' (' id ' int (one) not null auto_increment, ' content ' longtext not null, PRIMARY KEY (' id ')) ENGINE =innodb auto_increment=16 DEFAULT charset=latin1 |+----------+---------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -------------+1 Row in Set (0.00 sec)
Because the character set of the table itself is latin1
Another problem is that the mysql> in the strong state of the input of Chinese language will appear garbled, such as:
After testing, the strain is the problem of the system, close all the shells, and then reopen the problem solved!
=============================================================
Previous experiments: [[email protected] ~]# cat/etc/sysconfig/i18nlang= "ZH_CN. GB2312 "#LANG =" en_US. UTF-8 "sysfont=" Latarcyrheb-sun16 "[[email protected] ~]# mysql-uroot-p123-e" show variables like ' character_set_ %‘;" +--------------------------+----------------------------------+| variable_name | Value |+--------------------------+----------------------------------+| character_set_client | gb2312 | | character_set_connection | gb2312 | | Character_set_database | UTF8 | | Character_set_filesystem | binary | | Character_set_results | gb2312 | | Character_set_server | UTF8 | | Character_set_system | UTF8 | | Character_sets_dir | /usr/local/mysql/share/charsets/|+--------------------------+----------------------------------+[[email Protected] ~]# mySql-uroot-p123welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 31Server version:5.5.20-log Source distributioncopyright (c) #, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> show variables like ' character_set_% '; +------------------------- -+----------------------------------+| variable_name | Value |+--------------------------+----------------------------------+| character_set_client | gb2312 | | character_set_connection | gb2312 | | Character_set_database | UTF8 | | Character_set_filesystem | binary | | Character_set_results | gb2312 | | Character_Set_server | UTF8 | | Character_set_system | UTF8 | | Character_sets_dir | /usr/local/mysql/share/charsets/|+--------------------------+----------------------------------+8 rows in Set ( 0.00 sec) mysql> set names UTF8; Query OK, 0 rows Affected (0.00 sec) mysql> Show variables like ' 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/local/mysql/share/charsets/|+--------------------------+----------------------------------+8 rows in Set ( 0.00 sec) mysql> mysql> exit #退出再登陆 Find and restore the original character set so, say set names * * * is temporary bye[[email protected] ~]# MYSQL-UROOT-P12 3Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 32Server version:5.5.20-log Source distributioncopyright (c) #, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> show variables like ' character_set_% '; +------------------------- -+----------------------------------+| variable_name | Value |+--------------------------+----------------------------------+| character_set_client | gb2312 | | Character_set_connection | gb2312 | | Character_set_database | UTF8 | | Character_set_filesystem | binary | | Character_set_results | gb2312 | | Character_set_server | UTF8 | | Character_set_system | UTF8 | | Character_sets_dir | /usr/local/mysql/share/charsets/|+--------------------------+----------------------------------+8 rows in Set ( 0.00 sec) Mysql> below if on behalf of--default-character-set=utf8 [[email protected] ~]# mysql-uroot-p123-- Default-character-set=utf8welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 33Server version:5.5.20-log Source distributioncopyright (c) #, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for Help. Type ' \c ' to clear the current input statement.mysql> show variables like ' 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/local/mysql/share/charsets/|+--------------------------+----------------------------------+8 rows in Set ( 0.00 sec) Mysql> In fact, it is the same as set names * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Permanent settings [[email protected] ~]#Sed-en '/client|default-characte/p '/etc/my.cnf# the following options would be passed to all MySQL Clients[client]default -character-set = UTF8 #在client下增加 [[email protected] ~]# See the character set of the Linux system as follows [[email protected] ~]# cat/etc/ Sysconfig/i18nlang= "ZH_CN. GB2312 "#LANG =" en_US. UTF-8 "sysfont=" Latarcyrheb-sun16 "[[email protected] ~]# mysql-uroot-p123-e" show variables like ' character_set_ %‘;" +--------------------------+----------------------------------+| variable_name | Value |+--------------------------+----------------------------------+| character_set_client | UTF8 [clinet] | | character_set_connection | UTF8 [clinet] | | Character_set_database | UTF8 [mysqld] | | Character_set_filesystem | binary | | Character_set_results | UTF8 [client] | | Character_set_server | UTF8 [mysqld] | | Character_set_system |UTF8 | | Character_sets_dir | /usr/local/mysql/share/charsets/|+--------------------------+----------------------------------+ You can see that the character set is unified and the end is MySQL server: but need to restart [[email protected] ~]# sed-ne '/mysqld|^character-set/p '/etc/my.cnf[mysqld] Character-set-server = UTF8 #在/etc/my.cnf [mysqd] Add # If all processes this need to connect to mysqld run on the same ho st.# all interaction with mysqld must be made via Unix sockets or named pipes.# (via the "enable-named-pipe" option) would Render Mysqld useless! [mysqldump] only reboot to load the configuration file into memory where the server is changed character_set_database and Character_set_server two. Also changed the character set of the Linux system: [[email protected] ~]# cat/etc/sysconfig/i18n#lang= "ZH_CN. GB2312 "lang=" en_US. UTF-8 "sysfont=" Latarcyrheb-sun16 "[[email protected] ~]# source/etc/sysconfig/i18n
Count the library garbled problem