MySQL Limits

As a central component of the popular LAMP Stack, MySQL is a very versatile and popular database server. It can be easily configured to handle a relatively large number of users and is used by many high profile companies including Facebook, Youtube, Alcatel and many others. See https://www.mysql.com/customers/

One drawback, however is the default LAMP installation does not allow that many mysql connections or handle large databases well. The following configuration changes allows mysql to handle a fairly large database (500-800 tables) and user load (5000-10000 users).

These changes are suggested for RHEL / CentOS 7

  • Update my.cnf

nano /etc/my.cnf

max_connections = 500
key_buffer_size = 2048M
table_definition_cache = 4K
open_files_limit = 3K
query_cache_size = 128M
query_cache_limit = 128M
join_buffer_size = 4M
  • Update system limits on open files

To increase edit nano /etc/sysctl.conf add the below line, save and exit:

fs.file-max = 100000
  • Update mysql user limits on files and processes opened
Edit /etc/security/limits.conf add the below lines before the #End, save and exit:
mysql hard nofile 1024000
mysql soft nofile 1024000
  • Make the changes effective:
sudo systemctl daemon-reload
  • Restart mysql server
systemctl restart mysqld.service
%d bloggers like this: