您的位置:首页 > 数据库 > MySQL

查看 MySQL 表使用的存储引擎

2011-11-09 11:55 411 查看
转自: 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 创建。

Fifi的博客

实例演示如下:

Fifi的博客

MySQL 服务器基本情况:

MySQL 服务器未启用 InnoDB 存储引擎;

测试数据库库名: mytest ;

测试数据库表名: test ( mytest.test ) ;

测试数据库登录帐号: root ;

测试数据帐号登录密码: mypassword ;

Fifi的博客

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

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

Fifi的博客

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

01.
mysql> SHOW  ENGINES;

02.
+------------+---------+----------------------------------------------------------+(省略部分结果)

03.
| Engine     | Support | Comment                                                  |(省略部分结果)

04.
+------------+---------+----------------------------------------------------------+(省略部分结果)

05.
| InnoDB     | NO      | Supportstransactions, 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 asof MySQL 3.23 with great performance|(省略部分结果)

13.
+------------+---------+----------------------------------------------------------+(省略部分结果)

14.
8 rowsin set (0.00 sec)

15.

16.
mysql>

17.



2. 创建表 "test"

Fifi的博客

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.
-> idINT(11)default NULL auto_increment,

07.
-> schar(60)default NULL,

08.
-> PRIMARY KEY (id)

09.
-> ) ENGINE=InnoDB;

10.
Query OK, 0 rowsaffected, 2 warnings(0.06 sec)

11.
mysql>

12.



Fifi的博客

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

Fifi的博客

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>


Fifi的博客

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

01.
ansen@neusoft:/myhome$ mysql -uroot -p'mypassword'

02.
Welcome to the MySQL monitor.  Commandsend with ; or \g.

03.
Your MySQL connection idis221

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>


Fifi的博客

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

Fifi的博客

1.
ansen@neusoft:/myhome$ mysqlshow  -uroot -p'mypassword'   --statusmytest 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$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: