How to reduce memory consumption in MySQL

Time:2021-4-14

preface

By default, MySQL will initialize a large memory block to cache database query data.

But my small host only has 640MB of memory. Top query found that he ate 30% of my total memory, almost 200MB.

But there are only a few MB of data in this database. I feel that this setting is unreasonable.

After crawling, the memory usage is reduced to 128MB

Implementation method

Modify / etc / MySQL directly/ mysql.conf .d/ mysqld.cnf

Add the following configuration at the end of configuration


performance_schema_max_table_instances=150
table_definition_cache=150
table_open_cache=64

Then service MySQL restart can restart the service

effect

Before optimization

After optimization

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]