MySQL的每個(gè)數(shù)據(jù)庫目錄中有一個(gè)文件db.opt,該文件主要 用來存儲(chǔ)當(dāng)前數(shù)據(jù)庫的默認(rèn)字符集和字符校驗(yàn)規(guī)則。
eg.default-character-set=latin1
default-collation=latin1_swedish_ci
該文件中存儲(chǔ)的是創(chuàng)建數(shù)據(jù)庫時(shí)默認(rèn)的字符集和字符集校驗(yàn)規(guī)則,則該數(shù)據(jù)庫在以后創(chuàng)建表時(shí)如果沒有指定字符集和校驗(yàn)規(guī)則,則該表的這兩個(gè)屬性將去自這兩個(gè)表。
MySQL源碼:
/* 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;
}
創(chuàng)建數(shù)據(jù)庫時(shí)指定字符集和字符集校驗(yàn)規(guī)則:
create database if not exists test default [charset|character set ] utf8 default collate utf8_general_ci;
修改數(shù)據(jù)庫的字符集和字符集校驗(yàn)規(guī)則:
alter database test default [charset|character set ] latin1 default collate latin1_swedish_ci;
創(chuàng)建數(shù)據(jù)庫create database
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] …
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
也可以通過alter database修改
ALTER {DATABASE | SCHEMA} [db_name]
alter_specification …
alter_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name 本文出自:億恩科技【www.cmtents.com】
MySQL源碼:
/* 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;
}
創(chuàng)建數(shù)據(jù)庫時(shí)指定字符集和字符集校驗(yàn)規(guī)則:
create database if not exists test default [charset|character set ] utf8 default collate utf8_general_ci;
修改數(shù)據(jù)庫的字符集和字符集校驗(yàn)規(guī)則:
alter database test default [charset|character set ] latin1 default collate latin1_swedish_ci;
創(chuàng)建數(shù)據(jù)庫create database
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification] …
create_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
也可以通過alter database修改
ALTER {DATABASE | SCHEMA} [db_name]
alter_specification …
alter_specification:
[DEFAULT] CHARACTER SET [=] charset_name
| [DEFAULT] COLLATE [=] collation_name 本文出自:億恩科技【www.enidc.com】 -->
服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]
|