最近租了一台128兆内存的虚拟主机,没有直接用MySQL,使用了它的替代品——MariaDB。
MariaDB版本使用的是10.5,默认占用内存87兆,还是有点高,参考了资料,简单修改了配置,内存占用22兆,可以接受。
Linux版本:Ubuntu 20.04
# 安装MariaDB
sudo apt install mariadb-server
# 重启MariaDB
sudo systemctl restart mariadb.service
配置文件如下,结合自己的配置修改
MariaDB重启之后,内存占用22兆
/etc/mysql/my.cnf
[mysqld]
performance_schema = off
key_buffer_size = 16M
query_cache_size = 2M
query-cache-limit = 1M
tmp_table_size = 1M
innodb_buffer_pool_size = 1M
innodb_log_buffer_size = 1M
max_connections = 25
sort_buffer_size = 512M
read_buffer_size = 256K
read_rnd_buffer_size = 512K
join_buffer_size = 128K
thread_stack = 196K
binlog_cache_size = 0M
参考
https://github.com/lowendbox/lowendscript
https://stackoverflow.com/questions/40189226/how-to-make-mysql-use-less-memory