1. Edit the MySQL configuration file
MySQL configuration file under Windows generally under the system directory or in the MySQL installation directory named my.ini, can be searched, Linux is generally/etc/my.cnf
--Add the following to the [Mysqld] tab:
Default-character-set = UTF8
Character_set_server = UTF8
Note: If something like "DEFAULT-CHARACTER-SET=GBK" already exists under this tab, just modify it.
--Add a line under the [MySQL] tab
Default-character-set = UTF8
--Add a line under the [Mysql.server] tab
Default-character-set = UTF8
--Add a line under the [Mysqld_safe] tab
Default-character-set = UTF8
--Add a line under the [Client] tab
Default-character-set = UTF8
2. Restart MySQL Service
Windows can operate in Service Manager, or you can use the command line:
net stop MySQL Enter
net start MySQL return
The service name may not necessarily be MySQL, please press your own settings
Linux is now using service MySQL restart
If a startup failure occurs, check that the configuration file has no setup errors
3. View Settings results
Log on to the MySQL command line client: Open command line
Mysql–uroot–p Enter
Enter password
Execute after entering MySQL: Show variables like "% character%";
The results should look similar to the following:
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
If the encoding is still not UTF8, check the configuration file or use the MySQL command to set it up:
Set character_set_client = UTF8;
Set character_set_server = UTF8;
Set character_set_connection = UTF8;
Set character_set_database = UTF8;
Set character_set_results = UTF8;
Set collation_connection = Utf8_general_ci;
Set collation_database = Utf8_general_ci;
Set collation_server = Utf8_general_ci;
Other than that:
You can use the following command when you create a database:
Create database app_relation character set UTF8;
Use app_relation;
SOURCE App_relation.sql;
The commands to modify the database encoding are:
ALTER DATABASE app_relation character set UTF8;
Set MySQL database encoding to UTF-8