In Linux, mysql has Chinese garbled characters. the default character set of MySQL after bitsCN.com is installed is latin1. to change its character set to what users need (such as utf8 ), you must modify the related configuration files. because the default installation directories of MySQL in linux are distributed in different files, you only need to modify the my. the INI file takes effect after it is restarted. so let's take a look at the MySQL database files, configuration files, and command files in different directories in linux:
1. the database directory where all the database files created are located
/Var/lib/mysql/
2. configuration file (mysql. server command and configuration file location)
/Usr/share/mysql
3. related commands (such as mysql mysqladmin)
/Usr/bin
4. startup script (for example, mysql startup command)
/Etc/rc. d/init. d/
View default character sets
# Mysql-u root-p
# (Enter the password)
Mysql> show variables like 'character _ set % ';
+ -------------------------- + ---------------------------- +
| 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 character set modification/etc/my. cnf file
#/etc/my.cnf[client]default-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0#default-character-set=utf8character-set-server=utf8init_connect='SET NAMES utf8'[mysql]no-auto-rehashdefault-character-set=utf8[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid
Remember: add character-set-server = utf8 to mysqld instead of default-character-set = utf8.
Otherwise, The following error will be reported: Starting MySQL... The server quit without updating PID file [failed] lib/mysql/localhost. localdomain. pid). exception
Restart the MySQL server to make the settings take effect.
#/Etc/init. d/mysql restart
BitsCN.com