You've already forked Epicnabbo-Catalogus-Updated-Daily
2.6 KiB
2.6 KiB
Optimizing MySQL for a 4 GB RAM VPS is crucial to ensure smooth performance, as the default settings are often too conservative. The most important setting to adjust is the InnoDB Buffer Pool Size, as it directly impacts how much data your database can cache in memory.
Key Settings to Optimize
Your primary goal is to allocate as much RAM as possible to the database's cache without causing the server to swap. A good starting point is to allocate 50% to 70% of your available RAM to the InnoDB Buffer Pool. For a 4 GB VPS, this means dedicating roughly 2 GB to 2.5 GB.
Here are the key settings you should adjust in your my.cnf or my.ini file.
[mysqld]
# InnoDB settings
# The most important setting. Set to 50-70% of total RAM.
innodb_buffer_pool_size = 2G
# The number of threads writing data from the buffer pool to the disk.
# A good starting value is 4 for modern systems.
innodb_io_threads = 4
# Amount of memory for the log buffer.
# A larger value can improve write performance for big transactions.
innodb_log_buffer_size = 16M
# Query Cache settings
# Recommended to disable since MySQL 5.7+ and deprecated in 8.0.
query_cache_type = 0
query_cache_size = 0
# Connection settings
# Maximum number of concurrent client connections.
# Adjust based on your expected traffic. A value of 150-250 is often suitable.
max_connections = 200
# Other settings
# A temporary table size limit to prevent memory exhaustion.
tmp_table_size = 64M
max_heap_table_size = 64M
Explanation of Settings
innodb_buffer_pool_size: This is the main data cache. The larger this is, the less MySQL has to read from the slower disk. Setting this to 2 GB is a solid choice for a 4 GB VPS, as it leaves enough RAM for the operating system and other services (like PHP-FPM and your web server).innodb_io_threads: This tells InnoDB how many threads to use for I/O operations. A higher number can improve performance on modern multi-core systems.query_cache_type/query_cache_size: The MySQL query cache is generally not recommended for most applications because it can often hurt performance due to the overhead of invalidating cached queries. It's best to disable it completely.max_connections: This setting controls how many users can connect to your database at the same time. Setting this too high can cause memory issues. You should monitor your database to see how many connections are typically active and set this value slightly higher than your peak usage.
After making these changes, restart your MySQL/MariaDB service for them to take effect.