The default Character Set of installed MySQL is latin1. To change the character set to what you need (such as utf8), you must change the related configuration file; in linux, the default installation directory of MySQL is distributed in different files. Unlike in windows, you only need to modify 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