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

MySQL存储引擎

2015-11-18 15:34 615 查看
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