如何为Ubuntu配置mysql配置(RAM:4GB CPU:2VCPU SSD磁盘:80GB)

时间:2018-05-26 09:55:44

标签: mysql ubuntu-16.04

我试图提高我的mysql性能。所以我添加了更多内存。但在某些方面仍然缓慢。我最左边的加入和更新。

我的数据库有40GB的数据。

我当前的mysql配置是:

key_buffer              = 1024M
max_connections         = 3000
query_cache_size        = 256M
query_cache_limit       = 512M
thread_stack            = 32M 
innodb_buffer_pool_size =  512M
innodb_lock_wait_timeout= 150

table_cache = 2048
max_allowed_packet = 16M
max_heap_table_size = 64M
binlog_cache_size = 1M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency = 8
thread_stack = 192K
query_cache_size = 128M
query_cache_type = 1
query_cache_limit = 2M
tmp_table_size = 64M
key_buffer_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G

问题是。这是最好的配置吗?

MY Serve正在运行:Digitalocean / Ubuntu16.04

RAM:4GB CPU:2VCPU SSD磁盘:80GB

2 个答案:

答案 0 :(得分:0)

Suggestions for your my.cnf-ini [mysqld] section from the limited information posted in the original question,

thread_cache_size=50  # from 8 and monitor threads_created
thread_concurrency=16  # from 8 and monitor response time

# LEAD the following lines to allow DEFAULTS to work for you
# key_buffer=1024M  # lead with # to ignore, you have only 4G RAM
# max_connections=3000  # lead with # for default of 151, until more needed
# sort_buffer_size=8M
# read_buffer_size=2M
# read_rnd_buffer_size=8M
# join_buffer_size=8M
# thread_stack=32M

Take two minutes at www.mysqlcalculator.com to see how the above values unnecessarily increase your RAM footprint for each connection. DEFAULTS frequently work very well for you.

答案 1 :(得分:0)

根据我的个人经验,最好的方法是描述一些最慢的查询,并检查它们为什么慢。有时您使用的是“where”(查询条件)而没有任何索引,有时您添加/更新值时需要更新的索引太多。

请注意,每个字段都应基于您正在运行的内容。一个非常虚拟的例子。 max_allowed_pa​​cket = 16M

如果您没有批量查询或不使用Blob,可以将其缩小。但是如果你存储大斑点,你需要这么大,以适应你将存储的更大的附件。