First, view the current database encoding
Show variables like '%character% ';
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/3E/wKiom1c8A-7SxbjFAAAlDd_yQtY266.png "title=" 1.png " alt= "Wkiom1c8a-7sxbjfaaaldd_yqty266.png"/>
You can see the default character_set_database encoding format, where you can see that the default is Latin1.
Modify the encoding of a database and enter it under the database, such as Greenpass
Modify to gb2312 encoding mode:
Mysql>use Greenpass;
Mysql>alter database Greenpass character Set gb2312;
Mysql>show variables like ' character_set_database ';
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/3F/wKiom1c8CM-h5vFUAAAYJT1FisM831.png "title=" 4.png " alt= "Wkiom1c8cm-h5vfuaaayjt1fism831.png"/>
Modify to Utf-8 encoding mode:
mysql> ALTER DATABASE Greenpass character set UTF8;
mysql> flush Privileges;
Mysql>show variables like ' character_set_database ';
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/3C/wKioL1c8CqOhk0pIAAAX75KQb7Y365.png "title=" 5.png " alt= "Wkiol1c8cqohk0piaaax75kqb7y365.png"/>
Second, modify the configuration file
-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
Restart the MySQL service.
3. Database Code Verification
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;
This article is from the Linux Technical Exchange blog, so be sure to keep this source http://9678130.blog.51cto.com/9668130/1774721
MySQL database encoding