The following is a summary of MySQL character set operation commands that are run in mysql 5.5 command line:
View the character sets supported by MySQL:
Show charset;
View character set:
Status
The following is more specific:
Show variables like 'character _ set _ % ';
View the sorting method:
Show variables like 'collation _ % ';
The default character set is generally used when the database is created, unless it is specified at the time of creation:
Create database [db-name] character set utf8 COLLATE utf8_general_ci;
Specify the character set when creating a table:
Create table [table-name] (id int not null) default charset utf8;
View the character set used by the database:
Method 1: Find the directory where the database is stored, enter the Directory of the corresponding database, and view the database. opt file.
Method 2:
Show create database [db-name];
View the character set of the table:
Show create table [table-name];
View the character set of each table in the database:
Show table status from [db-name];
If the character set is not described after each column, the character set of the column is the same as that of the table.
You can also specify a table:
Show table status from [db-name] like '% filter % ';
View the character set of each column in the table:
Show full columns from [table-name];
Or
Show table status from [db-name];
Modify the database character set:
Alter database [db-name] default character set [character-name] COLLATE [collation-name];
Modify the character set of tables and columns (fields:
Alter table [table-name] convert to character set [character-name] COLLATE [collation-name];
Only modify the character set of the table:
Alter table [table-name] default character set [character-name] COLLATE [collation-name];
Others: you can modify the default character set of mysql to the desired character set, such as UTF-8. when creating a table, the character set of the table uses the character set of the database by default. However, I personally think the better way is to set up the character set used by the database when creating the database. we should not ignore this query when writing the program:
Set names 'utf8 ';