Knowledgebase


Portal Home > Knowledgebase > General > Tune MySQL

Tune MySQL

Mysql set up (“my.cnf”). The MySQL config file, my.cnf.

Here is what to add under the [mysqld] heading.

The two lines, “max_connections” and “max_user_connections” are where the magic happens.
Since your Apache/PHP box is connecting to MySQL, it appears as a single user.

MySQL defaults to 1 max connection, with 1 max connection per user. The following lines make it so your Apache/PHP box can connect to your MySQL box up to the number you have set “MaxClients” to in the Apache config above. By using persistent connections, you can pretty much get Apache up,  have it connect to MySQL upon start up, and just use the persistent connections to pass data between  the two boxes rather than opening connections. Its much more efficient that way.

set-variable = max_connections = 300
(this must be higher than “MaxClients” set in Apache, or you won’t fully maximize use)
set-variable = max_user_connections = 300
set-variable = table_cache=1200
(max number of tables in join multiplied by max_user_connections)

A few other MySQL tunings:

set-variable = max_allowed_packet=1M (sanity check to stop runaway queries)
set-variable = max_connect_errors=999999
(stop mysqld from shutting down if there are connect errors – this defaults to 1 error and mysqld stops!)

This is the only needed info

There are 5 tags in my.cnf

max_connections

max_user_connections

table_cache

max_allowed_packet

ax_connect_errors


Also Read