当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL笔记九:MySQL存储引擎

MySQL笔记九:MySQL存储引擎

2020年07月17日  | 移动技术网IT编程  | 我要评论

MySQL存储引擎

MySQL体系架构

  • 网络连接层
  • 服务处
  • 存储引擎层
  • 系统文件层

存储引擎

myisam

  • 5.5版本之前系统表默认的存储引擎
  • 不支持 事务 主外键
  • 表锁
  • MYD文件:数据文件 ,MYI文件:索引文件
  • 适合只读类应用

innodb

  • 5.5版本之后默认的存储引擎
  • 支持事务 外键
  • 使用表空间进行存储
    • show innodb_file_per_table
    • 独立表空间:默认
    • 系统表空间
  • 支持行锁

csv

  • 文本方式存储
  • 不支持自增
  • 不支持索引
  • 字段不能为null
  • 不建议直接修改文件,用命令去操作

memory

  • 数据保存到内存中
  • 支持hash和btree索引
    • hash:适合等值查询
    • btree:适合范围查询
  • 固定长度:varchar(10)=char(10)
  • 不支持大字段 TEXT/BLOB

如何选择存储引擎

  • 1.看需不需要事务
  • 2.备份
  • 3.崩溃恢复
  • 应用举例
    • 日志型应用:myisam
    • 只读或者大部分情况下只读的表:myisam
    • 订单处理:innodb

涉及到的命令行

-- 查看表状态
check table tablename  

-- 修复表
repair table tablename 

-- 查看表空间
show variables like 'innodb_file_per_table';

-- 关闭独立表空间
set global innodb_file_per_table=off;

-- 命令行修改的话,是临时修改,重启mysql的话还是一样的,不会真正的修改,要去配置文件修改才是真正的修改。

-- 创建表的时候可以指定引擎
create table test(id int(10)) engine='innodb';

-- 单位时间内处理的事务数(TPS)
show global status like 'Com_commit'; 
show global status like 'Com_rollback'; 

-- 单位时间内处理的查询数(QPS)
show  global  status like 'Question%'; 

-- 刷新表
flush tables;

-- 基准测试
mysqlslap --concurrency=1,50,100,200 --iterations=3 --number-int-cols=5 --number-char-cols=5 --auto-generate-sql
--auto-generate-sql-add-autoincrement --engine=myisam,innodb --number-of-queries=10 --create-schema=test 

mysqlslap --no-defaults -hlocalhost -uroot -proot -P3306 --concurrency=1,50,100,200 --iterations=3 --number-int-cols=5 --number-char-cols=5 --auto-generate-sql --auto-generate-sql-add-autoincrement --engine=myisam,innodb --number-of-queries=10 --create-schema=test --only-print |more

本文地址:https://blog.csdn.net/xiaoduu/article/details/107374170

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网