Environment: CentOS 6.3, mysql5.1
Centos 6.3 After installing MySQL client and server, garbled, have to modify the encoding.
Attention:
About the difference between UTF8 and GBK detailed: Linux Chinese garbled problem resolution http://www.linuxidc.com/Linux/2010-04/25757.htm, the following configuration in accordance with their own requirements to choose two encodings.
Steps to resolve:
1. Find the MySQL configuration file, copy to/etc directory, the first step is very important
Use the Find command to find the CNF file. Remember not to look for my.cnf because it does not necessarily exist, but should find *.cnf.
[Email protected]_mysql ~]# Find/-iname "*.CNF"-print
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-innodb-heavy-4g.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-large.cnf
/usr/share/doc/mysql-server-5.1.61/my-huge.cnf
/usr/share/doc/mysql-server-5.1.61/my-small.cnf
/usr/share/doc/mysql-server-5.1.61/my-innodb-heavy-4g.cnf
/usr/share/doc/mysql-server-5.1.61/my-medium.cnf
/usr/share/doc/mysql-server-5.1.61/my-large.cnf
/etc/pki/tls/openssl.cnf
/etc/my.cnf
Once found, copy one out
[Email protected]_mysql ~]# cp/usr/share/doc/mysql-server-5.1.61/my-medium.cnf/etc/my.cnf
CP: Do you want to overwrite "/etc/my.cnf"? Y
2. Open/ETC/MY.CNF To modify the configuration file:
[Email protected]_mysql ~]# vim/etc/my.cnf
Add under [client]
Default-character-set=utf8
Add under [mysqld]
Default-character-set=utf8
: Wq #保存
3. Restart MySQL
Depending on how you install MySQL, use the unused commands to restart your MySQL. If you have configured to use the Mysqld self-boot method, you can perform
[Email protected]_mysql ~]#/etc/rc.d/init.d/mysqld restart
Stop mysqld: [OK]
Starting mysqld: [OK]
MySQL is configured as a system service, performing
[R[email protected]_mysql ~] #service mysqld Restart
Stop mysqld: [OK]
Starting mysqld: [OK]
4. Log in to MySQL to see if the changes were successful
[Email protected]_mysql ~]# mysql-u root-p
Enter Password: (enter password)
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/|
+---------------------------------------+--------------------------------------------+
8 rows in Set (0.00 sec)
Mysql>
Configuration Complete!
Troubleshooting MySQL garbled in CentOS (Linux)