title: Waiting for table level lock on a MySQL table
body: <p>The last few days, at random times my website has become very slow. I started to investigate the best I could. I saw that the MySQL process was using 85 - 95% of the available memory of my server (should I upgrade my memory also?).</p>
  
  <p>I checked my MySQL process log, and I noticed a huge list of queries with:</p>
  
  <blockquote>
    <p>Waiting for table level lock</p>
  </blockquote>
  
  <p>But what I also noticed, what that ALL of these queries with "table level lock", was only queries which had something to do with my table called <code>users</code>.</p>
  
  <p>I have 20 other tables, with constant queries, but I don't see them on the list.. So I guess the problem is with the users table?</p>
  
  <p>I want to know how I can improve the table, and eventually remove the table level lock?</p>
  
  <p>I also ran this:</p>
  
  <pre><code>SHOW VARIABLES LIKE 'query_cache%';
  </code></pre>
  
  <p>Which resulted in this:</p>
  
  <pre><code>query_cache_limit
  1048576
  query_cache_min_res_unit
  4096
  query_cache_size
  33554432
  query_cache_type
  ON
  query_cache_wlock_invalidate
  OFF
  </code></pre>
  
  <p>Please let me know what I can do to improve my database/mysql. </p>
  
  <p>This is a list of the processes: </p>
  
  <pre><code>   | 228 | db_user | localhost | db_db| Query          |    5 | Waiting for table level lock | SELECT count(*) FROM users WHERE createtime&gt;'1396411200' OR createtime='1396411200'                  |
      | 229 | db_user | localhost | db_db| Query          |    4 | Waiting for table level lock | UPDATE users SET upline_clicks=upline_clicks+'1', upline_earnings=upline_earnings+'0.0000' WHERE use |
  | 203 | db_user | localhost | db_db| Query          |    6 | Waiting for table level lock | SELECT SUM(cashedout) FROM users                                                                     |
  | 204 | db_user | localhost | db_db| Query          |    4 | Waiting for table level lock | UPDATE users SET upline_clicks=upline_clicks+'1', upline_earnings=upline_earnings+'0.0000' WHERE use |
  | 205 | db_user | localhost | db_db| Query          |    1 | Waiting for table level lock | SELECT * FROM users WHERE id='12055'                                                                 |
  | 206 | db_user | localhost | db_db| Query          |    2 | Waiting for table level lock | SELECT * FROM users WHERE id='22530'                                                                 
  | 197 | db_user | localhost | db_db| Query          |    3 | Waiting for table level lock | SELECT * FROM `users` WHERE `username` = 'ptc4life123' LIMIT 1                                       |
  | 200 | db_user | localhost | db_db| Query          |    3 | Waiting for table level lock | UPDATE users SET upline_clicks=upline_clicks+'1', upline_earnings=upline_earnings+'0.0050' WHERE use |
  </code></pre>
  
  <p>This is basically what all the locked processes looks like.</p>