All of the following runs through the MySQL 5.5 command line:
To view MySQL-supported character sets:
Copy Code code as follows:
View Character Set:
Copy Code code as follows:
The following are more specific:
Copy Code code as follows:
Show VARIABLES like ' character_set_% ';
To see how to sort:
Copy Code code as follows:
Show VARIABLES like ' collation_% ';
The default character set is typically used when the database is established, unless specified at the time of establishment:
Copy Code code as follows:
CREATE DATABASE [db-name] CHARACTER SET UTF8 COLLATE utf8_general_ci;
Specify the character set when setting up table:
Copy Code code as follows:
CREATE TABLE [table-name] (id int not null) default CharSet UTF8;
To view the character set used by the database:
Method 1: Locate the directory where the database is stored, enter the directory of the corresponding databases, and view the db.opt file.
Method 2:
Copy Code code as follows:
Show CREATE DATABASE [Db-name];
To view the character set of a table:
Copy Code code as follows:
Show CREATE TABLE [Table-name];
To view the character sets for each table in the database:
Copy Code code as follows:
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 the table.
You can also specify a table:
Copy Code code as follows:
Show table status from [Db-name] like '%filter% ';
To view the character sets for each column in the table:
Copy Code code as follows:
Show full columns from [Table-name];
Or
Copy Code code as follows:
Show table status from [Db-name];
To modify the database character set:
Copy Code code as follows:
ALTER DATABASE [db-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];
To modify the character set of tables and columns (fields):
Copy Code code as follows:
ALTER TABLE [Table-name] CONVERT to CHARACTER SET [Character-name] COLLATE [collation-name];
Just modify the character set of the table:
Copy Code code as follows:
ALTER TABLE [table-name] DEFAULT CHARACTER SET [character-name] COLLATE [collation-name];
Other: You can modify MySQL's default character set for your own needs of the character set, such as Utf-8, when the table's character set defaults to use the database's character set. However, personally feel that the better way is to set up the database when the database to use the character set, we write the program, do not ignore this query:
Copy Code code as follows: