【拯救捉襟见肘的内存!】MySQL禁用InnoDB的方法

LAMP教程微魔在之前的文章中分享了一些MySQL的错误解决方法,最近在使用DireVPS的过程中又发生了类似的问题,虽然商家的标配是512M内存,但是因为众多原因(说明白就是超售咯),内存严重吃紧。特别是微魔尝试在上面玩Magento,被性能完爆(环境采用的是VestaCP),不过现在具体原因还不能一味的贵在商家身上,因为微魔发现VestaCP在性能,特别是MySQL经常出现问题(比如MySQL停止的问题)。回到正题,既然内存无法满足MySQL那就只有禁用InnoDB(MySQL自5.5后已经默认采用InnoDB作为数据库引擎),有鉴于网上现在很多教程还是针对5.1或者更早的版本,一些方法已经有了变化,因此微魔特别撰写本文,针对的版本是5.5和5.6。

如果你执意要玩儿Magento,Innodb引擎是不可缺少的…所以本文不适用Magento用户,请自行升级内存配置

0.确定版本

查看MySQL版本

mysql -V

或者可以登录MySQL使用select version();或status;命令查看

1.开始工作

关闭MySQL

service mysql stop

如果上面的命令无法关闭MySQL,则使用kill -9命令强制杀掉进程;

修改MySQL配置文件my.cnf(通常位于/etc/mysql/my.cnf)下加入如下字段

对于MySQL 5.5而言

default-storage-engine=MyISAM
loose-skip-innodb

loose-innodb-trx=0 
loose-innodb-locks=0 
loose-innodb-lock-waits=0 
loose-innodb-cmp=0 
loose-innodb-cmp-per-index=0
loose-innodb-cmp-per-index-reset=0
loose-innodb-cmp-reset=0 
loose-innodb-cmpmem=0 
loose-innodb-cmpmem-reset=0 
loose-innodb-buffer-page=0 
loose-innodb-buffer-page-lru=0 
loose-innodb-buffer-pool-stats=0

对于MySQL 5.6而言

default-storage-engine=MyISAM
default-tmp-storage-engine=MYISAM
loose-skip-innodb

loose-innodb-trx=0 
loose-innodb-locks=0 
loose-innodb-lock-waits=0 
loose-innodb-cmp=0 
loose-innodb-cmp-per-index=0
loose-innodb-cmp-per-index-reset=0
loose-innodb-cmp-reset=0 
loose-innodb-cmpmem=0 
loose-innodb-cmpmem-reset=0 
loose-innodb-buffer-page=0 
loose-innodb-buffer-page-lru=0 
loose-innodb-buffer-pool-stats=0 
loose-innodb-metrics=0 
loose-innodb-ft-default-stopword=0 
loose-innodb-ft-inserted=0 
loose-innodb-ft-deleted=0 
loose-innodb-ft-being-deleted=0 
loose-innodb-ft-config=0 
loose-innodb-ft-index-cache=0 
loose-innodb-ft-index-table=0 
loose-innodb-sys-tables=0 
loose-innodb-sys-tablestats=0 
loose-innodb-sys-indexes=0 
loose-innodb-sys-columns=0 
loose-innodb-sys-fields=0 
loose-innodb-sys-foreign=0 
loose-innodb-sys-foreign-cols=0

2.查看成效

登录MySQL

mysql -uroot -p你的密码

显示使用的数据库引擎

show engines
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| InnoDB             | NO      | Supports transactions, row-level locking, and foreign keys     | NULL         | NULL | NULL       |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| MyISAM             | DEFAULT | MyISAM storage engine                                          | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

猜你 喜欢

关于作者: 微魔

小微魔,大智慧!

多条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注