请问各位有没有珍藏的 MySQL5.7 优化的配置文件?可否分享?能在 700MB 内存云机器跑的那种。我搜了些资料,凑了个配置放帖子里了,求帮忙看看

31 天前
 0x0208v0

实测占用 200 ~ 300MB 之间,不知道还有没有更优化的配置。。。

MySQL 这个玩意儿,应该有很多黑魔法的吧?

要不然市面上那些 500MB 内存的小 VPS ,或者什么网站空间是怎么部署的?

配置文件内容如下:


#################################################
# 参考链接:
# https://stackoverflow.com/questions/60244889/how-to-decrease-mysql-container-memory-usage
# https://github.com/alexanderkoller/low-memory-mysql
#################################################

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


#### These optimize the memory use of MySQL
#### http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html
innodb_buffer_pool_size=5M
innodb_log_buffer_size=256K
query_cache_size=0
max_connections=10
key_buffer_size=8
thread_cache_size=0
host_cache_size=0
innodb_ft_cache_size=1600000
innodb_ft_total_cache_size=32000000

# per thread or per operation settings
thread_stack=131072
sort_buffer_size=32K
read_buffer_size=8200
read_rnd_buffer_size=8200
max_heap_table_size=16K
tmp_table_size=1K
bulk_insert_buffer_size=0
join_buffer_size=128
net_buffer_length=1K
innodb_sort_buffer_size=64K

#settings that relate to the binary log (if enabled)
binlog_cache_size=4K
binlog_stmt_cache_size=4K

#### from https://mariadb.com/de/node/579
performance_schema = off

620 次点击
所在节点    程序员
4 条回复
0x0208v0
31 天前
这是 docker-composel.yaml 文件,也限制了内存
```
version: '3'
services:
mysql:
image: mysql:5
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql_data:/var/lib/mysql
- ./mysql.cnf:/etc/mysql/conf.d/my.cnf
environment:
MYSQL_ROOT_PASSWORD: Y3Zv5l7ZJFiC
ports:
- 3306:3306
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
deploy:
resources:
limits:
cpus: '0.50'
memory: 500M
reservations:
cpus: '0.25'
memory: 200M

```
ShallowAi
31 天前
1. 关闭或限制 binlog 大小
2. 使用 mariadb 替代,实测容器环境下,版本 11.3.2 ,内存占用量 63MB 左右,在旧版本 11.1.2 有一定连接数的情况下占用 205MB 左右
0x0208v0
30 天前
@ShallowAi 谢谢大佬,我试试
czhh
30 天前
蹲一下|・ω・`)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1032757

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX