本人入手的搬瓦工内存仅128M,装了LNMP后发现MySQL经常会崩溃,因为MySQL5.5后默认使用Innodb引擎,虽然这个引擎有很多优点,但是相比MyISAM,无论是启动还是运行,需要占用更多的内存,在服务器内存捉襟见肘的时候,如果对Innodb的特性(如事务支持)并没有特别要求的情况下,换成MyISAM无疑是更好的选择:

MySQL5.5 修改/etc/my.cnf如下,[mysql]节:

[mysql]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
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

key_buffer = 16K
query_cache_limit = 256K
query_cache_size = 4M
max_allowed_packet = 1M
table_cache = 8

max_connections = 16
thread_concurrency = 2

sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K

修改后重启mysqld,
在日志中可以看到innodb已经被禁用了。

151228 2:58:10 [Note] Plugin 'InnoDB' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_TRX' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_LOCK_WAITS' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_CMP' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_CMP_RESET' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_CMPMEM' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_CMPMEM_RESET' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_BUFFER_PAGE' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_BUFFER_PAGE_LRU' is disabled.
151228 2:58:10 [Note] Plugin 'INNODB_BUFFER_POOL_STATS' is disabled.

注意:如果之前的Wordpress的表用的是innodb引擎的,Wordpress默认状态下是使用该引擎的,需要在禁用前先将表转换成MyISAM,我写了一个Wordpress插件将这个工作简化了, 如果转换失败,请确认wp-config.php中的mysql用户是否有权限alter table.

插件github地址:https://github.com/falconchen/wp_alert_table_engine
插件osc.git地址:http://git.oschina.net/falcon/wp_alert_table_engine

求fork,求start 🙂

- EOF -