Create a mysql database problem

Database client tools navicate

1. Use create database statement to create a database

(1) specified character marks Collection

create [database|schema ]if not exists 数据库名 default character set = 'utf8';
Note: DB character set is specified by the default character set = statement.

(2) specify the character set and collation designated character set name [ collation optional ]

create [database|schema ]if not exists 数据库名 default character set = 'utf8' collate utf_bin|gbk_chinese_ci;

 2. Check the creation of the character set of the DB

select schema_name, default_character_set_name from information_schema.schemata where schema_name = database name; 
Note: The system table view schemata know, DB character set is utf8 at the same time, the database character set is utf8, then create a table in the database. character sets are also utf8 that is the character set of the database table for subsequently created is influential.

 3. When you do not specify the character set to build the table

  Did not specify when construction of the table, will use the default character set of the database, if the database character set is not set, the database server will use the default character set 

4. Check the database creation information: show create database + database_name.
    Modify the character set: alter database + database_name character set gbk ;
    Check system character set: show variables like 'character_set_%' ;

5. modify the character set mode:

Modify the default character set table:

ALTER TABLE table_name DEFAULT CHARACTER SET character_name;

Modify the default character set table field:

ALTER TABLE table_name CHANGE field field field_type CHARACTER SET character_name [other_attribute]

Modify the table default character set and all character sets columns:

ALTER TABLE table_name CONVERT TO CHARACTER SET character_name

Character set changes to the database
    MySQL> use mydb
    MySQL> ALTER Database mydb Character SET UTF-. 8;
create database character set specified database
    mysql> create database mydb character set utf -8;

modified through the configuration file:
Modify / var / lib / mysql /mydb/db.opt
default Character-SET = latin1-
default-collation = latin1_swedish_ci
as
default Character-SET = UTF8-
default-collation = utf8_general_ci
restart the MySQL:
[bogon the root @ ~] # /etc/rc.d/init .d / mysql restart

Guess you like

Origin www.cnblogs.com/xiaozengzeng/p/12042180.html