Each MySQL database directory contains a file db. opt, which is mainly used to store the default Character Set and character verification rules of the current database. Eg. default-character-s
Each MySQL database directory contains a file db. opt, which is mainly used to store the default Character Set and character verification rules of the current database. Eg. default-character-s
Each MySQL database directory contains a file db. opt, which is mainly used to store the default Character Set and character verification rules of the current database.
Eg. default-character-set = latin1
Default-collation = latin1_swedish_ci
This file stores the default Character Set and character set validation rules when creating a database. If the database does not specify the character set and validation rules when creating a table in the future, the two attributes of the table are derived from the two tables.
MySQL source code:
/* Set table default charset, if not set
SYNOPSIS
Set_table_default_charset ()
Create_info Table create information
DESCRIPTION
If the table character set was not given explicitely,
Let's fetch the database default character set and
Apply it to the table .*/
Static void set_table_default_charset (THD * thd,
HA_CREATE_INFO * create_info, char * db)
{
If (! Create_info-> default_table_charset)
{
HA_CREATE_INFO db_info;
Load_db_opt_by_name (thd, db, & db_info );
Create_info-> default_table_charset = db_info.default_table_charset;
}
Specify Character Set and character set verification rules when creating a database:
Create database if not exists test default [charset | character set] utf8 default collate utf8_general_ci;
Modify the character set and character set verification rules of the database:
Alter database test default [charset | character set] latin1 default collate latin1_swedish_ci;
Create database
CREATE {DATABASE | SCHEMA} [if not exists] db_name
[Create_specification]…
Create_specification:
[DEFAULT] character set [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
You can also use alter database to modify
ALTER {DATABASE | SCHEMA} [db_name]
Alter_specification...
Alter_specification:
[DEFAULT] character set [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
,