转自:
http://www.open2open.org/index.php/db/mysql/53-usemysql/79-mysqltableengine.html

2010年 11月 24日 星期三 23:30:17

        网上有很多类似于《查看 MySQL 表使用的存储引擎》的文章,不过都不严谨。使用 “SHOW CREATE TABLE 表名”  查看。这种方式查出的结果在某些情况下是不准确的。

比如创建表 "test"

1.
CREATE TABLE test (
2.
id INT(11) default NULL auto_increment,
3.
s char(60) default NULL,
4.
PRIMARY KEY (id)
5.
) ENGINE=InnoDB;

 

一般情况这样没任何问题。但是,如果MySQL服务器在配置中,未启用 InnoDB 存储引擎。在创建表 "test" 时,MySQL会自动选择默认的存储引擎 MyISAM 创建。

实例演示如下:

MySQL  服务器基本情况:

  • MySQL 服务器未启用  InnoDB   存储引擎;
  • 测试数据库库名:   mytest  ;
  • 测试数据库表名:   test ( mytest.test )  ;
  • 测试数据库登录帐号:  root  ;
  • 测试数据帐号登录密码:   mypassword  ;

 

        列 "Engine" 下显示的值表示表正在使用的 MySQL 存储引擎。在未启用  InnoDB  存储引擎的情况下,我们可以发现正确的方式返回的结果里面,列 "Engine" 为 "MyISAM",并不是 "InnoDB"  存储引擎。所以,使用 “SHOW CREATE TABLE 表名”  查看表使用的  MySQL  存储引擎是不准确的。

1.     确认 MySQL 服务器 是否启用 InnoDB   存储引擎

        返回结果是:  "InnoDB"   对应的  "Support"等于 “NO”  ,表示未启用  InnoDB  存储引擎。

01.
mysql> SHOW  ENGINES;
02.
+------------+---------+----------------------------------------------------------+(省略部分结果)
03.
| Engine     | Support | Comment                                                  |(省略部分结果)
04.
+------------+---------+----------------------------------------------------------+(省略部分结果)
05.
| InnoDB     | NO      | Supports transactions, row-level locking, and foreign keys|(省略部分结果)
06.
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                  |(省略部分结果)
07.
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disa(省略部分结果)
08.
| CSV        | YES     | CSV storage engine                                       |(省略部分结果)
09.
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables|(省略部分结果)
10.
| FEDERATED  | NO      | Federated MySQL storage engine                           |(省略部分结果)
11.
| ARCHIVE    | YES     | Archive storage engine                                   |(省略部分结果)
12.
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance|(省略部分结果)
13.
+------------+---------+----------------------------------------------------------+(省略部分结果)
14.
8 rows in set (0.00 sec)
15.
 
16.
mysql>
17.

 

2.     创建表 "test"

01.
mysql> create database mytest;
02.
Query OK, 1 row affected (0.02 sec)
03.
mysql> use mytest;
04.
Database changed
05.
mysql> CREATE TABLE test (
06.
-> id INT(11) default NULL auto_increment,
07.
-> s char(60) default NULL,
08.
-> PRIMARY KEY (id)
09.
-> ) ENGINE=InnoDB;
10.
Query OK, 0 rows affected, 2 warnings (0.06 sec)
11.
mysql>
12.


 

3.     使用不准确的方式: “SHOW CREATE TABLE 表名”  查看

 

01.
mysql> SHOW CREATE TABLE test;
02.
+-------+----------------------------------------------------------------------------+
03.
| Table | Create Table|
04.
+-------+----------------------------------------------------------------------------+
05.
| test  | CREATE TABLE `test` (
06.
`id` int(11) NOT NULL AUTO_INCREMENT,
07.
`s` char(60) DEFAULT NULL,
08.
PRIMARY KEY (`id`)
09.
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
10.
+-------+----------------------------------------------------------------------------+
11.
1 row in set (0.00 sec)
12.
mysql>

 

4.     正确方式一:  SHOW TABLE STATUS from  数据库库名  where Name='表名';

01.
ansen@neusoft:/myhome$ mysql -uroot -p'mypassword'
02.
Welcome to the MySQL monitor.  Commands end with ; or \g.
03.
Your MySQL connection id is 221
04.
Server version: 5.1.41-3ubuntu12.7 (Ubuntu)
05.
 
06.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
07.
 
08.
mysql> SHOW TABLE STATUS from mytest where Name='test';
09.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
10.
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length |(省略部分结果)
11.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
12.
| test | MyISAM |      10 | Fixed      |    0 |              0 |           0 |(省略部分结果)
13.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
14.
1 row in set (0.02 sec)
15.
 
16.
mysql>

 

5.     正确方式二:  mysqlshow  -u 数据库登录帐号 -p '数据库登录帐号密码'   --status   数据库库名   表名

 

1.
ansen@neusoft:/myhome$ mysqlshow  -uroot -p'mypassword'   --status mytest test
2.
Database:mytest  Wildcard: test
3.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
4.
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length |(省略部分结果)
5.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
6.
| test | MyISAM |      10 | Fixed      |    0 |              0 |           0 |(省略部分结果)
7.
+------------+--------+---------+------------+------+----------------+-------------+(省略部分结果)
8.
ansen@neusoft:/myhome$