Mysql takes 100 % CPU

I have seen that when executing a mysql query the cpu usage becomes 100 % and it takes a long time to execute the query.  I have executed the same query thorugh phpmyadmin and that time also it took a long time to execute also mysql consumes 100 % cpu .  I have done some change to my.cnf file and restarted mysql and the problem wentaway.  You can also adjust your my.cnf values as follows.

[mysqld]
max_allowed_packet = 128M
sort_buffer_size = 512M
max_connections=500
query_cache_size = 512M
query_cache_limit = 512M
query-cache-type = 2
table_cache = 80
thread_cache_size=8
key_buffer_size = 512M
read_buffer_size=64M
read_rnd_buffer_size=64M
myisam_sort_buffer_size=64M
innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=700M
innodb_additional_mem_pool_size=20M

Once you made the changes in my.cnf do not forget to restart mysql server. Mysql can be restarted in any of the following methods

If you have installed mysql using RPM you can restart mysql using one of the following commands

service mysqld restart  OR /etc/init.d/mysqld restart

If you have installed mysql from source files you  can shutdown mysql and start it as follows

Stop Mysql : mysqladmin -uroot -p shutdown

Start msyql : /usr/local/mysql/bin/mysqld_safe –user=mysql &   (assume mysql is installed at /usr/local/mysql)

You can leave a response, or trackback from your own site.

Leave a Reply

Subscribe without commenting


Fatal error: Call to undefined function wp_list_addonn() in /home/sites/customers/aneesh/systemadmin/blog/wp-content/themes/Grante/sidebar.php on line 106