14.8.1 Creating InnoDB Tables  创建InnoDB 表

创建一个InnoDB表,使用CREATE TABLE 语句,你不需要指定ENGINE=InnoDB 子句 

如果InnoDB 是定义为默认的存储引擎,在MySQL 5.5是默认为InnoDB.

你仍旧可以使用 ENGINE=InnoDB clause 如果你计划使用mysqldump或者复制 来重现CREATE TABLE 在一个server上

那个server 默认不是InnoDB 存储引擎

-- Default storage engine = InnoDB.
CREATE TABLE t1 (a INT, b CHAR (20), PRIMARY KEY (a)); -- Backward-compatible with older MySQL.
CREATE TABLE t2 (a INT, b CHAR (20), PRIMARY KEY (a)) ENGINE=InnoDB; 在一个InnoDB 表和他的索引可以创建在系统表空间或者一个 file-per-table tablespace. 当 innodb_file_per_table 启用时,一个InnoDB 表时隐式的创建在一个单独的 file-per-table tablespace. 相反,当innodb_file_per_table is disabled, 一个InnoDB 表时隐式的创建在系统表空间。 当你创建一个InnoDB 表,MySQL 创建一个 .frm file 在一个数据库目录在MySQL data directory.目录下。 一个.ibd文件也会被创建 一个表创建在 system tablespace 是创建在存在的system tablespace ibdata files. 在内部, InnoDB 增加一个条目对于每个表到InnoDB 的数据字典。 条目包含数据库名字 比如,如果表t1是创建在test数据库下, 数据目录条目是'test/t1'. 这意味着你能创建相同的名字的表在不同的数据库,表名字在InnoDB内部不冲突 mysql> SHOW TABLE STATUS FROM test LIKE 't%' \G;
*************************** 1. row ***************************
Name: t1
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 0
Avg_row_length: 0
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 0
Auto_increment: NULL
Create_time: 2015-03-16 16:26:52
Update_time: NULL
Check_time: NULL
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec) 在这个状态输出,你可以看到 表t1的hang格式属性是 Compact 尽管设置是好的对于基本的实验,使用动态或者压缩行格式来利用InnoDB的功能 比如表压缩和off-page storage 用于long列的值 使用那些行格式需要innodb_file_per_table 启用 mysql> SHOW TABLE STATUS FROM zjzc like 'Client'\G;
*************************** 1. row ***************************
Name: Client
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 13244
Avg_row_length: 436
Data_length: 5783552
Max_data_length: 0
Index_length: 3620864
Data_free: 3145728
Auto_increment: 13778
Create_time: 2016-10-28 09:46:59
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment: 用户表 1 row in set (0.00 sec) ERROR:
No query specified SET GLOBAL innodb_file_per_table=1;
SET GLOBAL innodb_file_format=barracuda;
CREATE TABLE t3 (a INT, b CHAR (20), PRIMARY KEY (a)) ROW_FORMAT=DYNAMIC;
CREATE TABLE t4 (a INT, b CHAR (20), PRIMARY KEY (a)) ROW_FORMAT=COMPRESSED; Defining a Primary Key for InnoDB Tables 定义一个主键在InnoDB 表上 1.总是设置一个主键对于每个InnoDB表,指定列或者多列 2. 被用于最重要的查询 3.永远不会是空的 4.不会有重复值 5.很少改动一旦插入后 例如, 在一个表包含信息关于people, 你不能创建一个主键在(firstname, lastname) 因为不止一个人有相同的名字, 有些人last name是空白的,有些人会改变它们的名字。 有这么多的约束, 没有一个明显的列来使用作为主键。 因此你可以创建一个数据列ID 来作为主键,你可以定义一个自增列

14.8.1 Creating InnoDB Tables 创建InnoDB 表的更多相关文章

  1. 14.6.1 Creating InnoDB Tables 创建InnoDB 表:

    14.6.1 Creating InnoDB Tables 创建InnoDB 表: 创建一个InnoDB 表,使用CREATE TABLE 语句,你不需要指定 ENGINE=InnoDB子句 如果In ...

  2. 14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器

    14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器 这个章节描述技术关于移动或者复制一些或者所 ...

  3. 14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构

    14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构 一个InnoDB 表的物理行结构取决于在创建表指定的行格式 默认, Inno ...

  4. 14.6.7?Limits on InnoDB Tables InnoDB 表的限制

    14.6.7?Limits on InnoDB Tables InnoDB 表的限制 警告: 不要把MySQL system tables 从MyISAM 到InnoDB 表. 这是不支持的操作,如果 ...

  5. 14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器

    14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器 这个章节描述技术关于移动或者copy ...

  6. 14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用

    14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用 Vsftp:/data01/mysql/zjzc# ls -lt ...

  7. 14.2.5.1 Role of the .frm File for InnoDB Tables InnoDB .frm文件的作用

    14.2.5.1 Role of the .frm File for InnoDB Tables: 14.2.5.1 Role of the .frm File for InnoDB Tables I ...

  8. 14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小

    14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小 这个章节描述如何增加或者减少 InnoDB 系统表空间的大小 增加InnoDB ...

  9. 14.6.11 Configuring Optimizer Statistics for InnoDB 配置优化统计信息用于InnoDB

    14.6.11 Configuring Optimizer Statistics for InnoDB 配置优化统计信息用于InnoDB 14.6.11.1 Configuring Persisten ...

随机推荐

  1. web程序记录当前在线人数

    在页面上显示当前在线人数 效果: 1.Global.asax文件: <%@ Application Language="C#" %><%@ Import Name ...

  2. Memcache简介

    简介 Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像.视频.文件以及数据库检索的结果等.简单的说就是将数据调 ...

  3. 28、Jquery 页面效果

    Jquery动画函数分为三类 基本动画函数 基本动画函数包括show(显示).hide(隐藏).toggle(切换)这三个函数. 例子所需html <input type="butto ...

  4. CSS之关于clearfix--清除浮动

    一,什么是.clearfix 你只要到Google或者Baidu随便一搜"css清除浮动",就会发现很多网站都讲到"盒子清除内部浮动时可以用到.clearfix" ...

  5. Javascript基础学习(2)_表达式和运算符

    1.==和===的区别(!=和!==是相反的比较) 它们采用了同一性的两个不同定义.==是相等性,===是等同性. ①“===”进行两个值的比较 两个值的类型不同,就不相等 两个值是数字,并且值相同, ...

  6. NodeJS学习笔记—2.AMD规范

    CommonJS加载模块是同步的,而AMD模块加在是非同步的,允许指定回调函数.由于Nodejs主要用于服务器编程,模块文件一般都存在于本地,所以加载很快,不需要考虑非同步加载,用CommonJS即可 ...

  7. C++ sizeof总结

    关键字sizeof的作用是返回对象或类型占用的内存字节数,返回值是size_t. 基本数据类型占用的字节数:(32位系统) char 1字节 bool 1字节 short 2字节 int 4字节 lo ...

  8. js日期格式,日期对象

    以对象为基准去使用方法, 围绕Date对象 var a = new Date() 返回当前的时间对象,可以使用内置的日期对象的方法 a.getFullYear(), a.getMonth(), a.g ...

  9. Lua与C/C++交互问题

    初学lua,遇到注册C/C++交互函数问题 在lua与C/C++交互时,C/C++的注册Lua函数若是一个有返回类型(压栈)而不是获取类型的时候应该返回1而不是返回0,否则会出现在Lua中值为nil( ...

  10. Codeforces 551D GukiZ and Binary Operations(矩阵快速幂)

    Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的 ...