The Caching of MySQL queries

Nov 27, 2007 16:45 GMT  ·  By

MySQL databases are widely used in server side application development due to their well known features. The databases and server maintenance is a very important aspect that influences in a direct manner your applications' performance and stability.

Usually, MySQL databases are used with applications developed in PHP programming language, but they can also be managed with other server side programming languages such as ASP (Active Server Pages), ASP.NET, JSP, Python, Ruby and more. The main performance issue that appears in case of almost any database driven application running on server side is determined by server configuration.

The existence of multiple queries in the same time over a single database can produce various errors when your site is very crowded. There are two possibilities to improve the speed and stability of your application from the database queries point of view: you can use the application caching mechanisms or enable the caching of MySQL queries on the server side.

MySql query cache records a SELECT statement and the result sent to a page visitor. When an identical query is performed later, it is retrieved in query cache and the time to execute the query is visible reduced. If the server side application based on MySQL databases does not have its own caching mechanism, the MySQL query cache seems to be the best alternative to assure a certain performance level.

Alongside MySQL query cache, the tables and threads cache will play also an important role when you want to increase the speed of execution of various queries in case of databases having a big number of tables and as a consequence all others specific MySQL server parameters must be set according to the database structure.

Even if you are not used to MySQL server command line directives, in order to setup the MySQL cache size you can use any visual configuration tool, such as MySQL Administrator available for many operating systems. From within this application, after you connect to your MySQL server, select the Performance tab and set the cache size. It is recommended a value higher than 32 MB, but depending on server performance, you must monitor the free memory and the cache value should be established as a function of free memory value.

In conclusion, you will notice an improvement of your application having a MySQL database backend when you will enable the Mysql query cache, disabled by default. This operation must be made usually after a new MySQL server installation but if you do not have administrative privileges, you'd better select a server side application having its own caching mechanisms, which will lead to similar performance results.