MySQL存储引擎
2015-11-18 15:34
615 查看
MySQL事物自动提交
MySQL常用存储引擎:MyISAM 和 InnoDB(特性ACID)
MyISAM引擎调优
1、设置合适的索引。
2、调整读写优先级,根据实际需求确保重要操作优先执行。
3、启用延迟插入改善大批量写入性能。
4、尽量顺序操作让insert数据都能写入尾部,减少阻塞。
5、分解大的时间长的操作,降低单个操作的阻塞时间。
6、降低并发数。
7、对于更改不频繁的数据,利用Query Cache缓存服务缓存数据。
InnoDB引擎调优
1、主键尽可能小。
2、避免全表扫描。
3、尽可能缓存索引和数据,减小IO。
4、尽可能自己控制事物而不使用自动提交。
5、合理设置 innodb_flush_log_at_trx_commit 参数。0:性能最好 | 1:安全最高 | 2:类似Oracle
6、避免主键更新,因为这样会带来大量数据移动。
批量修改MySQL引擎
mysql> show variables like '%auto%' ; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | sql_auto_is_null | OFF | +-----------------------------+-------+ 7 rows in set (0.00 sec) mysql> set autocommit=1; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%auto%'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | sql_auto_is_null | OFF | +-----------------------------+-------+ 7 rows in set (0.00 sec) mysql> set autocommit=0; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%auto%'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | OFF | | automatic_sp_privileges | ON | | innodb_autoextend_increment | 8 | | innodb_autoinc_lock_mode | 1 | | sql_auto_is_null | OFF | +-----------------------------+-------+ rollback; 回滚事物 commit; 提交事物
MySQL常用存储引擎:MyISAM 和 InnoDB(特性ACID)
mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 8 rows in set (0.00 sec)
MyISAM引擎调优
1、设置合适的索引。
2、调整读写优先级,根据实际需求确保重要操作优先执行。
3、启用延迟插入改善大批量写入性能。
4、尽量顺序操作让insert数据都能写入尾部,减少阻塞。
5、分解大的时间长的操作,降低单个操作的阻塞时间。
6、降低并发数。
7、对于更改不频繁的数据,利用Query Cache缓存服务缓存数据。
InnoDB引擎调优
1、主键尽可能小。
2、避免全表扫描。
3、尽可能缓存索引和数据,减小IO。
4、尽可能自己控制事物而不使用自动提交。
5、合理设置 innodb_flush_log_at_trx_commit 参数。0:性能最好 | 1:安全最高 | 2:类似Oracle
6、避免主键更新,因为这样会带来大量数据移动。
--分表,一个表一个数据文件。 mysql> show variables like '%innodb_file_per_table%'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_file_per_table | ON | +-----------------------+-------+ 1 row in set (0.00 sec)
批量修改MySQL引擎
1、ALTER TABLE t1 ENGINE = InnoDB ALTER TABLE t1 ENGINE = MyISAM 2、nohup sed -e 's/MyISAM/InnoDB/g' backup.sql > backup_new.sql & 3、/application/mysql/bin/mysql_convert_table_format
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复