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
Modify the/etc/my. cnf File
#/Etc/my. cnf
[Client]
Default-character-set = utf8
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
User = mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
Symbolic-links = 0
# Default-character-set = utf8
Character-set-server = utf8
Init_connect = 'set NAMES utf8'
[Mysql]
No-auto-rehash
Default-character-set = utf8
[Mysqld_safe]
Log-error =/var/log/mysqld. log
Pid-file =/var/run/mysqld. pid
Remember: What is added to mysqld is
Character-set-server = utf8 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