400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

MySQL储存引擎MyISAM和InnoDB配置

MySQL 存储引擎 MyISAM 和 InnoDB 配置


MyISAM 和 InnoDB 最大特点:

MyISAM :

① 不支持事务 。

② 表级锁定形式 ,数据在更新时锁定整个表 。

③ 不支持外键约束 ,只支持全文索引 。

④ 数据库在读取过程中相互阻塞 。

⑤ 数据单独写入或读取 , 速度较快且占用资源相对要少 。

InnoDB:

① 支持事务 。

② 行级锁定 ,但是全表扫描仍然会是表级锁定 。

③ 支持分区、表空间 ,类似Oracle 数据库 。

④ 读写阻塞与事务隔离级别相关 。

⑤ 表与主键以簇的方式储存 。

⑥ 具有非常高效的缓存特性 ,能缓存引索 ,也能缓存数据 。

如何查看存储引擎:

查看 MySQL 默认存储引擎 :
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES      
查看 MySQL 支持的引擎以及默认存储引擎 。

查看表正在使用的存储引擎 :

方法一:
show table status from 库名 where name='表名';
mysql> show table status from jdy where name='test';
+------+--------+---------+------------+------+
| Name | Engine | Version | Row_format | Rows |
+------+-------------+-----------------+--------------+
| test | InnoDB |      10 | Dynamic    |    0 |                 # 表的存储引擎  InnoDB
方法二:
show create table 表名;
mysql> use jdy;          # 进入查看表的数据库
Database changed
mysql> show create table test;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                              |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE "test" (
 "name" varchar(10) DEFAULT NULL,
  "id" int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |          # 表的存储引擎  InnoDB

如何修改存储引擎:

mysql> use jdy;          # 进入查看表的数据库
Database changed
mysql> show create table test;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                              |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE "test" (
 "name" varchar(10) DEFAULT NULL,
  "id" int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |          # 表的存储引擎  InnoDB

#命令: alter table 表名 engine=引擎; 

mysql> alter table test engine=MyISAM;       #修改表的存储引擎为 MyISAM
Query OK, 0 rows affected (0.39 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table test;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                              |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| test  | CREATE TABLE "test" (
  "name" varchar(10) DEFAULT NULL,
  "id" int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |            #修改成功

方法二 :

vim /etc/my.cnf
[mysqld]
default-storage-engine=MyISAM   #添加指定默认存储引擎
mysql> create table test01 (id int );     #创建表
Query OK, 0 rows affected (0.00 sec)

mysql> show create table test01;
+--------+------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                             |
+--------+------------------------------------------------------------------------------------------+
| test01 | CREATE TABLE "test01" (
  "id" int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |       #创建的新表默认 MyISAM
设置默认存储引擎 ,创建的新表将使用 MyISAM 存储引擎 。

方法三 :

mysql> create table test02 (id int ) engine=InnoDB;
Query OK, 0 rows affected (0.35 sec)
mysql> show create table test02;
+--------+------------------------------------------------------------------------------------------+
| Table  | Create Table                                                                             |
+--------+------------------------------------------------------------------------------------------+
| test02 | CREATE TABLE "test02" (
  "id" int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |         #新表存储引擎是 InnoDB

方法四:


名称栏目:MySQL储存引擎MyISAM和InnoDB配置
文章起源:http://mzwzsj.com/article/gioeph.html

其他资讯

让你的专属顾问为你服务