Too many MySQL processes

Solution 1:

mysql     9804  0.0  0.6 58556 22960 pts/0   S    12:43   0:00  \_ /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/myhostname.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
mysql     9807  0.0  0.6 58556 22960 pts/0   S    12:43   0:00      \_ /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/myhostname.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
mysql     9808  0.0  0.6 58556 22960 pts/0   S    12:43   0:00          \_ /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/myhostname.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
mysql     9809  0.0  0.6 58556 22960 pts/0   S    12:43   0:00          \_ /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/myhostname.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
mysql     9810  0.0  0.6 58556 22960 pts/0   S    12:43   0:00          \_ /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/myhostname.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
[ ... repeated output truncated ... ]

They're not using 13 * 50mb of ram -- They're probably using something like 70mb total. Remember that that linux will share unmodified memory pages between processes, so if your server is freshly started most of that memory would all be shared. In fact, since mysql is threaded there will only probably be even less memory allocated per thread. If you're concerned about the memory usage of each mysql process, look at /etc/mysql/my.cnf, and look at the variables in the mysqld section:

  • key_buffers
  • thread_stack
  • thread_cache_size
  • max_connections
  • query_cache_limit
  • query_cache_size

Be warned though, that those are very powerful variables to tune, and you can easily kill your mysql performance setting them too low, or waste memory that could be used elsewhere by setting them too high.

One easy starting point to figure out the best way to tune your mysql instance is to run your app for a little bit, then run the mysqltune script from here, which will analyze your performance counters, then produce a recommendation on what you should change in your server config.

Solution 2:

Linux shows threads as separate processes. MySQL starts one thread per connection. Running ps with f. For example, ps auxfw will display how the threads are related.

How many connections are there to MySQL? Run show full processlist; in the MySQL client. From what you're showing, I'm not even confident that there's anything wrong.

Tags:

Mysql