最近安装了AliSQL,跑起来感觉没有怎么。但是top查看内存占用的时候,MySQL占用高达800M,但是服务器的配置是1H2G不经操,一旦高并发测试数据库直接占满内存就挂了需要手动重启。经过一番了解后,数据库配置文件默认是没有写的,需要自己去修改my.ini,可能习惯了宝塔环境一件自动优化,切到命令行感觉有点陌生了。

在宝塔环境可以了解到相关的参数,直接套用。

1performance_schema_max_table_instances = 200
2table_definition_cache = 100
3table_open_cache = 100

这三个参数调小后,可以感觉到内存明显降下来。

还可以关闭 performance_schema 数据库性能数据采集,调小innobd缓存池 innodb_buffer_pool_size=4M 还可以进一步降低内存占用。

PS: 我当前AliSQL使用的配置,可以大幅度降低内存到100M

 1# For advice on how to change settings please see
 2# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
 3[mysqld]
 4#
 5# Remove leading # and set to the amount of RAM for the most important data
 6# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
 7# innodb_buffer_pool_size = 128M
 8#
 9# Remove leading # to turn on a very important data integrity option: logging
10# changes to the binary log between backups.
11# log_bin
12#
13# Remove leading # to set options mainly useful for reporting servers.
14# The server defaults are faster for transactions and fast SELECTs.
15# Adjust sizes as needed, experiment to find the optimal values.
16# join_buffer_size = 128M
17# sort_buffer_size = 2M
18# read_rnd_buffer_size = 2M
19#
20# 数据库数据存放目录
21datadir=/var/lib/mysql
22socket=/var/lib/mysql/mysql.sock
23#
24#symbolic-links=0
25skip-external-locking
26key_buffer_size = 8M
27max_allowed_packet = 1M
28table_open_cache = 4
29sort_buffer_size = 64K
30read_buffer_size = 256K
31read_rnd_buffer_size = 256K
32net_buffer_length = 2K
33thread_stack = 240K
34#innodb_use_native_aio = 0
35innodb_buffer_pool_size=2M
36performance_schema_max_table_instances=50
37table_definition_cache=50
38table_open_cache=32
39max_connections=50
40max_user_connections=35
41wait_timeout=10
42interactive_timeout=15
43long_query_time=5
44performance_schema = off
45# Disabling symbolic-links is recommended to prevent assorted security risks
46symbolic-links=0
47# Recommended in standard MySQL setup
48sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
49[mysqld_safe]
50log-error=/var/log/mysqld.log
51pid-file=/var/run/mysqld/mysqld.pid

PS:如果你不修改datadirsocket数据目录为你设置的存放目录,可能会导致数据库不能正确启动。