It mainly solves the problem of Chinese garbled characters. The following command is to generate a uniform middot of gb2312; middot; replace gb2312 with gbk if you want to use gbk. Enter the command line mode, as shown in figure
It mainly solves the problem of Chinese garbled characters. The following command is to generate a uniform middot of gb2312; middot; replace gb2312 with gbk if you want to use gbk. Enter the command line mode, as shown in figure
It mainly solves the problem of Chinese garbled characters. The following command is unified into gb2312. If you want to use gbk, replace gb2312 with gbk.
Enter the command line mode ,,
If the MySQL database has been installed, you can use the following SQL command to view the current character set settings of MySQL:
Mysql> show variables like 'character _ set _ % ';
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
7 rows in set (0.00 sec)
Mysql> show variables like 'collation _ % ';
+ ---------------------- + ------------------- +
| Variable_name | Value |
+ ---------------------- + ------------------- +
| Collation_connection | latin1_swedish_ci |
| Collation_database | latin1_swedish_ci |
| Collation_server | latin1_swedish_ci |
+ ---------------------- + ------------------- +
3 rows in set (0.00 sec)
Run the following commands in sequence:
Set character_set_client = gb2312;
Set character_set_connection = gb2312;
Set character_set_database = gb2312;
Set character_set_results = gb2312;
Set character_set_server = gb2312;
Set character_set_system = gb2312; -- UTF-8 is also supported here.
Then execute:
SET collation_server = gb2312_chinese_ci
SET collation_database = gb2312_chinese_ci
SET collation_connection = gb2312_chinese_ci
--------------------------------- The following is a command to view and modify the MSQL database, table, and field encoding ---------------------
Mysql specifies the character set of database, table, and column by default when creating a database;
If the character set supported by the existing database does not meet the conditions, you can modify the character set of the database, table, and column. It is relatively easy to re-create the database if allowed,
Re-create database:
1. View character sets supported by the database
Mysql> SHOW CHARACTER SET
2. Create a database
Create database db_name default character set gbk COLLATE gbk_chinese_ci;
Or create database db_name default character set gbk;
3. When creating a table, the default Character Set of the table is the same as that of the database.
Modify existing databases and tables
1. View the character sets supported by the database:
Mysql> show create database lian;
Or mysql> show create database lian \ G;
2. Modify the character set of the database:
Mysql> alter DATABASE lian default character set gbk;
Note: If you create a table in the modified database, the new table uses the same character set as the database.
3. view the table character set. Pay attention to the column character set.
Mysql> show create table user_info;
4. Modify the table Character Set
Mysql> alter TABLE user_info default character set gbk;
5. Modify the column Character Set
Mysql> alter table user_info MODIFY id varchar (50) character set gbk not null;