Mysql database coding
1. View the current database code
show variables like '%character%';
You can see the default character_set_database encoding format, here you can see that the default is latin1.
Modify the encoding method of a database and enter it under the database, such as greenpass.
Modified to GB2312 encoding mode:
mysql>use greenpass;
mysql>alter database greenpass character set gb2312;
mysql>show variables like 'character_set_database';
Modified to utf-8 encoding mode:
mysql> alter database greenpass character set UTF8;
mysql> flush privileges;
mysql>show variables like 'character_set_database';
II. Modify the configuration file
- Add the following under the [mysqld] label:
default-character-set = utf8
character_set_server = utf8
Note: If something like "default-character-set=GBK" already exists under this label, just modify it.
--Add a line under the [mysql] tag
default-character-set = utf8
--Add a line under the [mysql.server] tag
default-character-set = utf8
--Add a line under the [mysqld_safe] label
default-character-set = utf8
--Add a line under the [client] label
default-character-set = utf8
Restart the MySQL service.
3. Database code verification
After entering mysql, execute: show variables like "% character %";
The result should look something like this:
| 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 there are still codes other than utf8, check the configuration file, or use the mysql command to set:
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;
In addition:
To create a database, you can use the following command:
create database app_relation character set utf8;
use app_relation;
source app_relation.sql;
The command to modify the database encoding is:
alter database app_relation character set utf8;