如何分析 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1012887/
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 to profile MySQL
提问by Dan
How do I profile a MySQL database. I want to see all the SQL being run against a database.
如何分析 MySQL 数据库。我想查看针对数据库运行的所有 SQL。
I know you can do this:
我知道你可以这样做:
set profiling=1;
- Run your slow query (eg
SELECT * FROM messages WHERE fromaddress='xxx';
SHOW PROFILES;
set profiling=1;
- 运行你的慢查询(例如
SELECT * FROM messages WHERE fromaddress='xxx';
SHOW PROFILES;
But this seem to only apply to stuff run on the command line, I want to see the results from running a website.
但这似乎只适用于在命令行上运行的东西,我想查看运行网站的结果。
采纳答案by Tom Ritter
回答by Matija
That worked for me on Ubuntu.
这在 Ubuntu 上对我有用。
Find and open your MySQL configuration file, usually /etc/mysql/my.cnf
on Ubuntu. Look for the section that says “Logging and Replication”
查找并打开您的 MySQL 配置文件,通常/etc/mysql/my.cnf
在 Ubuntu 上。查找“日志记录和复制”部分
# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
log = /var/log/mysql/mysql.log
or in newer versions of mysql, comment OUT this lines of codes
或在较新版本的 mysql 中,注释掉这行代码
general_log_file = /var/log/mysql/mysql.log
general_log = 1
log_error = /var/log/mysql/error.log
Just uncomment the log
variable to turn on logging. Restart MySQL with this command:
只需取消注释log
变量即可打开日志记录。使用以下命令重新启动 MySQL:
sudo /etc/init.d/mysql restart
Now we're ready to start monitoring the queries as they come in. Open up a new terminal and run this command to scroll the log file, adjusting the path if necessary.
现在我们准备开始监控进来的查询。打开一个新终端并运行此命令来滚动日志文件,如有必要调整路径。
tail -f /var/log/mysql/mysql.log
回答by Bryan Migliorisi
You can simply parse the query log in real time. If on linux, you can use tail -f to see the log live
您可以简单地实时解析查询日志。如果在 linux 上,您可以使用 tail -f 查看实时日志
Also, you can try some free software from these guys:
此外,您可以尝试这些人的一些免费软件:
回答by Haim Evgi
回答by buddy
MySqlAdministrator have some useful build in features (including logs view), but for logs it have to be run on same machine as database
MySqlAdministrator 有一些有用的内置功能(包括日志视图),但对于日志,它必须与数据库在同一台机器上运行