**************************************** ******************************
1. Starting MySQL... the server quit without updating PID File
After/etc/My. CNF is modified, start MySQL
#/Etc/init. d/MySQL start
Starting MySQL... the server quit without updating PID file [failed] B/MySQL/localhost. localdomain. PID ).
[Mysqld]
Character_set_server = utf8
View the MySQL Error Log
[Root @ localhost test1] # vi/var/lib/MySQL/localhost. localdomain. Err
We can see that
120516 16:26:11 [Error]/usr/sbin/mysqld: Unknown variable 'default _ set_server = utf8'
I checked it online and the netizen said mysql5 changed the character variable to character_set_server.
Use character_set_server = utf8 to replace default-character-set = utf8
Restart MySQL
#/Etc/init. d/MySQL start
Starting MySQL [OK]
**************************************** ******************************
2. MySQL Chinese garbled characters.
> Show variable like 'character % '; # display the code
+ ------------------------- + ---------------------------- +
| Variable_nam | value |
+ ------------------------- + ---------------------------- +
| Character_se_client | Latin1 |
| Character_se_connection | Latin1 |
| Character_se_database | Latin1 |
| Character_se_filesystem | binary |
| Character_se_results | Latin1 |
| Character_se_server | Latin1 |
| Character_se_system | utf8 |
| Character_ses_dir |/usr/share/MySQL/charsets/|
+ ------------------------- + ---------------------------- +
--------------
# Vi/etc/My. CNF
Find the client configuration [client] and add it below
### Default Character Set: utf8
Default-character-set = utf8
Add in [mysqld]
### Default Character Set: utf8
Default-character-set = utf8
### (Set utf8 encoding when connecting to the MySQL database to run the MySQL database as utf8)
Init_connect = 'set names utf8'
After modification, restart MySQL and query show variables like 'character % ';
# Restart MySQL
/Etc/init. d/MySQL restart
View encoding again
+ -------------------------- + ---------------------------- +
| 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/|
In this case, data insertion and query directly in the MySQL database console will not be garbled. However, the data inserted by a program written in C language is still garbled. When executing the SQL statement for inserting data, add
MySQL * pmydata; // msyql connection handle pmydata = mysql_init (null); mysql_query (pmydata, "set Character Set utf8"); // Add this sentence
In Linux, where is the location of the MySQL configuration file my. ini?
The MySQL configuration file is called my. ini in windows, and under the root directory of MySQL installation; under Linux, it is called my. CNF, which is located in/etc/My. CNF.
If you cannot find/etc/My. CNF, copy it.
# Cp/usr/share/MySQL/my-medium.cnf/etc/My. CNF
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************
**************************************** ******************************