I. Setting the encoding used by the database when creating the database
CREATE {database| SHECMA} [IF not EXISTS] Db_name
[DEFAULT] CHARACTER SET [=] Charset_name
Our default [] content is optional, which means it can be written without writing. You can also choose the encoding method, such as
[DEFAULT] CHARACTER SET [=] Charset_name
After such a setup, the code used in our database is gb2312, of course, you can also set other encoding methods, the main change charset_name just fine.
second, MySQL server can support multiple character sets
You can use the show CHARACTER Set statement to list the available character sets:
......
PS: Knowledge of character set and proofreading can be referred to the official reference manual
Iii. Viewing and modifying the encoding of fields in a MySQL database, table, table
MySQL, the database coding problem is more important, here is the main explanation of how to modify the database encoding, modify the table encoding and modify the table of a field encoding method, the need for a small partner can refer to.
1 . View the encoding of the current database and modify the database encoding.
We can see how the database is encoded before we make changes to the database encoding method.
First, you need to switch to a specific database (use db_name) before using the SQL statement:
SHOW VARIABLES like ' character_set_database ';
According to the show we know that the ABC database is encoded in UTF8.
The next step is to modify the encoding method, you can modify the database encoding, modify the way the table is encoded, modify the Table field encoding method (This ... A little messy, hehe, on)
First of all, modify the database encoding method:
ALTER {database| SHECMA} [Db_name] [DEFAULT] CHARACTER SET [=] Charset_name
You can see that the encoding in database ABC is now changed from UTF8 to gb2312.
2 . View the encoding of the table and the encoding of the modified table
First look at what tables are in the database ABC and use SQL statements;
SHOW TABLES:
Well, there is a mytable table, after creating a database, the database inside the default is empty, a table is not, then why appear table, haha, I this is a pre-created a table.
Then modify how the table is encoded, and first look at how the table is encoded:
There are two ways of doing this:
Mode 1:
Use db_name;
SHOW CREATE TABLE table_name;
Mode 2:
Use db_name;
Status
Database ABC table MyTable encoding method is UTF8, now we modify the encoding method:
ALTER TABLE mytable CHARACTER SET gb2312;
3 . Modify the encoding of the fields in the table:
MySQL Encoding Setup method