@derekleinbach
From looking at the defaults for a stock MySQL installation, max_connections
is set to 151
, so if at any time, there are more than 151
active connections to MySQL, you’ll receive that error.
Enabling query cache will help with select
statements (i.e. reads) as it caches the statement as well as the results. For example, if you had a broad select
statement such as:
select * from my_table
And that statement normally took 2.0 seconds to execute, with query cache enabled, it may only take a fraction of that, or 0.0 seconds next time around.
That being said, enabling query cache most likely won’t resolve your issue on its own. It will speed up frequent reads to your table(s) when someone checks if a date is available, but it won’t do anything when users are physically adding data to your database.
…
Back to max_connections
, you can raise this limit by modifying the MySQL configuration, though as a general note, the stock MySQL configuration isn’t really meant for production use – it’s meant to be a starting point for you to work with.
The more connections you allow, the more RAM MySQL is going to consume, so if you raise it too high you may very well run in to an issue of MySQL crashing due to OOM errors instead of maxing out the connection limit.
It’s a balancing act of sorts and there’s a lot of variables at play – some you need to pay more attention to than others, while some you need to just leave alone unless you have reason to modify them.
…
With that, what size is your current Droplet (i.e. RAM)?
I’d also recommend looking at MySQL Tuner. It’ll help you get a general idea of what’s going on and it’ll also make a few suggestions as to what you may need to tweak.
To install MySQL Tuner, choose a directory such as /opt
or perhaps /usr/local/src
and run:
wget http://mysqltuner.pl/ -O mysqltuner.pl \
&& wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/basic_passwords.txt -O basic_passwords.txt \
&& wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/vulnerabilities.csv -O vulnerabilities.csv \
&& perl mysqltuner.pl
Here’s the project: https://github.com/major/MySQLTuner-perl
Before running, ideally, MySQL should be running for at least 24-48 hours so the script has some data to work with.