mysql之CREATE DATABASE Syntax(创建数据库)
一:语法{ } create_specification:<span style="color: #ff0000">[<span style="color: #ff0000">DEFAULT<span style="color: #ff0000">] <span style="color: #0000ff">CHARACTER <span style="color: #0000ff">SET <span style="color: #ff0000">[<span style="color: #ff0000">=<span style="color: #ff0000">]<span style="color: #000000"> charset_name #指定字符集 <span style="color: #808080">| <span style="color: #ff0000">[<span style="color: #ff0000">DEFAULT<span style="color: #ff0000">] COLLATE <span style="color: #ff0000">[<span style="color: #ff0000">=<span style="color: #ff0000">] collation_name #specifies the default database collation (排序规则)例如:创建数据库并指定字符集 <span style="color: #0000ff">create <span style="color: #0000ff">database db2 <span style="color: #0000ff">default character set=utf8 备注:数据库的字符集存储在数据库目录下的db.opt文件中,我们可通过??find / -name db.opt? 查找并用less 查看相关db.opt文件如下
二:关于??CHARACTER SET? 和? ?COLLATE?三:查看相关字符集3.1 :查看MYSQL数据库服务器和数据库字符集? ? 方法一:show variables ;3.2 :查看表的字符集(show table status from 库名 like ?表名) show status test3 ;3.4 :查看表中所有列的字符集(show full columns from 表名;) show full columns from test3.students;注意:数值型的列没有 collation特性 四:修改相关的字符集4.1.创建时指定字符集 db2 test1(id (),name ()) ;4.2修改相关字符集 character_set_connection character_set_database character_set_results character_set_server<span style="color: #0000ff">set character_set_system<span style="color: #808080">=<span style="color: #000000">utf8; <span style="color: #0000ff">set collation_connection<span style="color: #808080">=<span style="color: #000000">utf8; <span style="color: #0000ff">set collation_database<span style="color: #808080">=<span style="color: #000000">utf8; <span style="color: #0000ff">set collation_server<span style="color: #808080">=utf8;4.3?修改库的字符集(alter database 库名 default character set 字符集;) mysql show . row : `shiyan` row (mysql<span style="color: #808080">> <span style="color: #0000ff">alter <span style="color: #0000ff">database shiyan <span style="color: #0000ff">default <span style="color: #0000ff">character <span style="color: #0000ff">set<span style="color: #000000"> gbk;Query OK,<span style="color: #800000; font-weight: bold">1 row affected (<span style="color: #800000; font-weight: bold">0.00 sec) 4.4修改表字符集(alter table 表名 convert to character set 字符集;) show create table test1G *************************** 1. row *************************** Table: test1 Create Table: CREATE TABLE `test1` ( `id` int(6) DEFAULT NULL,`name` char(10) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=gbk #原字符集 1 row in set (0.00 sec)mysql> alter table test1 convert to character set utf8; mysql> show create table test1G 4.5修改字段的字符集(alter table 表名 modify 字段名 字段属性 character set gbk;) test1 modify name () gbk;五:案例分析 当我们不知道因和原因创建的一个表(teacher),当我们向表中插入数据是发生乱码如下 sql : INSERT INTO teacher(tid,class_id,NAME)VALUE(312,2,'小明');
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- MYSQL保存特殊字符失败,用编码utf8mb4解决错误 Incorrect
- Mysql应用服务器数据库编码格式问题解决方案
- mysql – 如何创建Tab Delimited Select语句?
- MYSQL教程在MySQL数据库中复位根用户的密码的方法
- 全国最新区划数据-四级-省-市-县(区)-乡(镇)
- Mysql学习Centos 6.4源码安装mysql-5.6.28.tar.gz教程
- Mysql应用使用RPM包安装MySQL 5.7.18的教程
- Mysql学习重要的MySQL开发规范
- mysql – Laravel 5.1雄辩的关系模型 – 如何更新外键列?
- Mysql应用如何查看mysql编码与mysql版本