mysql中如何在创建数据库的时候指定数据库的字符集?

需求描述:

  在创建DB的时候指定字符集.

操作过程:

1.使用create database语句创建数据库

mysql> create database if not exists test03 default character set = 'utf8';
Query OK, 1 row affected (0.00 sec)

备注:通过default character set = 语句来指定DB的字符集.

2.查看创建的DB的字符集

mysql> select schema_name,default_character_set_name from information_schema.schemata where schema_name = 'test03';
+-------------+----------------------------+
| schema_name | default_character_set_name |
+-------------+----------------------------+
| test03      | utf8                       |
+-------------+----------------------------+
1 row in set (0.00 sec)

备注:通过系统表schemata查看可以知道,DB的字符集是utf8的.同时,数据库的字符集是utf8,那么在这个数据库下创建的表的字符集也都是utf8的.也就是数据库的字符集对于后续创建的表是有影响的.

文档创建时间:2018年6月1日14:27:07

原文地址:https://www.cnblogs.com/chuanzhang053/p/9121506.html