小内存VPS的mysql内存调优
有的VPS内存非常小,需要把mysql占用内存降到很低,比如30MB以内,/etc/my.cnf可以这样配置:
[mysqld]
default-storage-engine=MYISAM
default-tmp-storage-engine=MYISAM
# skip-innodb
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
loose-innodb-metrics=0
loose-innodb-ft-default-stopword=0
loose-innodb-ft-inserted=0
loose-innodb-ft-deleted=0
loose-innodb-ft-being-deleted=0
loose-innodb-ft-config=0
loose-innodb-ft-index-cache=0
loose-innodb-ft-index-table=0
loose-innodb-sys-tables=0
loose-innodb-sys-tablestats=0
loose-innodb-sys-indexes=0
loose-innodb-sys-columns=0
loose-innodb-sys-fields=0
loose-innodb-sys-foreign=0
loose-innodb-sys-foreign-cols=0
#skip-locking #old version
skip-external-locking
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
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 30
performance_schema_max_table_instances=100
table_definition_cache=20
table_open_cache=20
slow_query_log
long_query_time = 2
##slow_query_log_file="/tmp/mysql_slow.log"
##log_slave_updates
##gtid-mode=ON
##enforce-gtid-consistency=ON
explicit_defaults_for_timestamp=true
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
#safe-updates
[isamchk]
key_buffer = 8M
sort_buffer_size = 8M
[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
另外一个简单的配置,内存在150M以内
performance_schema = OFF
innodb_buffer_pool_size = 8M
innodb_additional_mem_pool_size = 1M
innodb_log_buffer_size = 1M
key_buffer_size = 0
query_cache_size = 0