# Strange MySQL behavior

**URL:** <https://forums.percona.com/t/strange-mysql-behavior/490>\
**Category:** Other MySQL® Questions\
**Created:** [October 16, 2007, 2:12am UTC](https://forums.percona.com/t/strange-mysql-behavior/490 "2007-10-16T02:12:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexN](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@AlexN](https://forums.percona.com/u/AlexN)\
**Post date:** [October 16, 2007, 2:12am UTC](https://forums.percona.com/t/strange-mysql-behavior/490/1 "2007-10-16T02:12:21Z")

</div>

Some days ago I encountered with a strange problem. MySQL and Apache resides both on the same server. In attempt to optimize MySQL someone increased the key buffer too much. Also the number of temp tables has been set too large.

At first it worked fine, but when the server load increased, Apache used some memory, while MySQL started to create temp tables on disk instead of memory. Queries took more time to complete, and new connections continued to arrive. In less than 20 minutes the whole server nearly stopped. There were about 20 running processes, all in the state “Copying to temp table”.

The question is: how to avoid such situation ? In, for example, MSSQL this scenario is hardly possible.

---

<div class="post-metadata">

**Author:** ![sterin](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@sterin](https://forums.percona.com/u/sterin)\
**Post date:** [October 16, 2007, 7:51am UTC](https://forums.percona.com/t/strange-mysql-behavior/490/2 "2007-10-16T07:51:39Z")

</div>

| [B]AlexN wrote on Tue, 16 October 2007 09:42[/B] |
| 

The question is: how to avoid such situation ? In, for example, MSSQL this scenario is hardly possible.

 |

Not true, if you set the memory usage limits for MSSQL to use more memory than you have RAM in the machine it will also bring the system to it's knees. It's a OS problem not a DBMS problem.

The problem is that you want to give the DBMS as much RAM memory as possible to use as cache to avoid disk IO.

_BUT_ if you set this value too high then the OS will start to swap and that will degrade performance _a\_lot_.

So it is better to stay on the safe side with the memory settings, especially since you are running Apache/PHP on the same server which also will consume unregular amounts of RAM.

---

<div class="post-metadata">

**Author:** ![AlexN](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@AlexN](https://forums.percona.com/u/AlexN)\
**Post date:** [October 16, 2007, 8:53am UTC](https://forums.percona.com/t/strange-mysql-behavior/490/3 "2007-10-16T08:53:28Z")

</div>

| [B]sterin wrote on Tue, 16 October 2007 09:21[/B] |
| 

So it is better to stay on the safe side with the memory settings, especially since you are running Apache/PHP on the same server which also will consume unregular amounts of RAM.

 |

Exactly. But where is the safe side ? As you correctly pointed, there are other programs on server that use unregular amounts of RAM. So when the load increases, the memory load can pass some threshold above which the system will go down.  
Is it a possible DOS-attack scenario ?

---

<div class="post-metadata">

**Author:** ![sterin](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@sterin](https://forums.percona.com/u/sterin)\
**Post date:** [October 18, 2007, 3:33am UTC](https://forums.percona.com/t/strange-mysql-behavior/490/4 "2007-10-18T03:33:37Z")

</div>

But that is not a DOS attack targeted against MySQL per se.

That is an attack targeted against the slow and weak parts of your application and it’s design.  
The fact that your application is using a database in the background is another matter.  
Because if you have bad PHP code (or whatever language you are using) you can target it the same way.

The attacker only knows that the page is slow and that is what he is attacking.

---

<div class="post-metadata">

**Author:** ![AlexN](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@AlexN](https://forums.percona.com/u/AlexN)\
**Post date:** [October 18, 2007, 4:56am UTC](https://forums.percona.com/t/strange-mysql-behavior/490/5 "2007-10-18T04:56:34Z")

</div>

| [B]sterin wrote on Thu, 18 October 2007 05:03[/B] |
| 

Because if you have bad PHP code (or whatever language you are using) you can target it the same way.

The attacker only knows that the page is slow and that is what he is attacking.

 |

Not really. Just PHP code will not cause that ‘avalanche’ scenario. The response time will increase more or less linear with increasing load.
