如何设置 MySQL 进程或线程的最大数量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/621516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set the max number of MySQL processes or threads?
提问by szabgab
ps axuw| grep mysql
indicates only MySQL process, but if I run htop I can see 10 rows each one of them with a separate PID. So I wonder if they are threads or processes that for some reason I cannot see using ps.
ps axuw| grep mysql
仅表示 MySQL 进程,但如果我运行 htop,我可以看到 10 行,每行都有一个单独的 PID。所以我想知道它们是否是由于某种原因我无法使用 ps 看到的线程或进程。
Would it make any sense to try to limit them to two on my development machine, where I don't need concurrent access of many clients.
在我的开发机器上尝试将它们限制为两个是否有意义,在那里我不需要许多客户端的并发访问。
BTW Running on Ubuntu 8.10
顺便说一句,在 Ubuntu 8.10 上运行
回答by Greg
You can set the max number of threads in your my.ini like this:
您可以像这样在 my.ini 中设置最大线程数:
max_connections=2
However you might also want to set this:
但是,您可能还想设置:
thread_cache_size=1
The thread cache controls how many it keeps open even when nothing is happening.
即使没有发生任何事情,线程缓存也会控制它保持打开状态的数量。
回答by Alnitak
MySQL does use threads, ps
can see them if you run ps -eLf
.
MySQL 确实使用线程,ps
如果您运行ps -eLf
.
That said, I wouldn't worry about it - dormant threads use almost no resources whatsoever, and if you constrain the server too much it's bound to come back and bite you on the backside sometime later when you've forgotten that you did it.
也就是说,我不会担心它 - 休眠线程几乎不使用任何资源,如果你对服务器限制太多,当你忘记你做了它时,它一定会在稍后的某个时候回来并咬你。
回答by jobwat
There is few configuration settings in /etc/mysql/my.cnf
that would impact memory usage.
Following settings:
key_buffer = 8M
max_connections = 30
query_cache_size = 8M
query_cache_limit = 512K
thread_stack = 128K
should drastically reduce the memory usage of mysql.
很少有配置设置/etc/mysql/my.cnf
会影响内存使用。以下设置:
key_buffer = 8M
max_connections = 30
query_cache_size = 8M
query_cache_limit = 512K
thread_stack = 128K
应该大幅减少mysql的内存使用。
read more here: http://opensourcehacker.com/2011/03/31/reducing-mysql-memory-usage-on-ubuntu-debian-linux/
在此处阅读更多信息:http: //opensourcehacker.com/2011/03/31/reducing-mysql-memory-usage-on-ubuntu-debian-linux/
回答by Benj
I was seeking for MySQL config stuff, then I saw this question.... Nothing to do with MySQL, am I right ?
我正在寻找 MySQL 配置的东西,然后我看到了这个问题......与 MySQL 无关,对吗?
If the main objective is to see the result of a custom command, you can use "watch" with the following syntax (available on most linux systems) :
如果主要目标是查看自定义命令的结果,您可以使用具有以下语法的“watch”(在大多数 linux 系统上可用):
watch "ps axuw| grep mysql"
It will run the command each 2 seconds and display the output, it is a very very useful command.
它将每 2 秒运行一次命令并显示输出,这是一个非常有用的命令。
-> See the doc/man to see how it's powerful ;)
-> 查看 doc/man 以了解它的强大功能;)