在128MB内存的VPS上折腾了一下MySQL,把过程总结一下记录下来。

1)配置文件
备份原配置文件,把官方配置样例中最低配置的配置文件复制过来,就可以了。命令如下:

mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf

2)禁用InnoDB
禁用InnoDB,为了节省内存。

详细参考:
小内存VPS上MySQL5.5内存优化——禁用Innodb引擎
http://hxs.fd.fj.cn/?action=show&id=48

简单来说,就是修改my.cnf,在[mysqld]下增加以下配置:

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

文中还提到MySQL 5.5,还需要添加以下配置,否则程序会很容易退出的:

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

3)设置默认字符集UTF-8
登录MySQL后,用以下命令查看字符集设置:

show variables like ‘character%’;

默认字符集一般是latin1,最简单是修改my.cnf文件
[client]增加:

default-character-set = utf8

[mysqld]增加:

character-set-server = utf8

[mysql]增加:

default-character-set = utf8

4)重启MySQL服务

PS. MySQL的错误日志在 /var/lib/mysql/*.err

标签: MySQL, VPS

评论已关闭