如何启动和检查我的 MySQL 日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9871718/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:43:14  来源:igfitidea点击:

How can I start and check my MySQL log?

mysqllogging

提问by Johnathan Au

I want to check the log in MySQL to see the queries that are being run by my application. How can I do this? I am using XAMPP and the directory to MySQL is C:\xampp\mysql.

我想检查 MySQL 中的日志以查看我的应用程序正在运行的查询。我怎样才能做到这一点?我正在使用 XAMPP,MySQL 的目录是 C:\xampp\mysql。

This is what I get when I do show variables like '%log%';

这就是我在做的时候得到的 show variables like '%log%';

mysql> show variables like '%log%';
+---------------------------------+------------------------------------+
| Variable_name                   | Value                              |
+---------------------------------+------------------------------------+
| back_log                        | 50                                 |
| binlog_cache_size               | 32768                              |
| binlog_format                   | STATEMENT                          |
| expire_logs_days                | 0                                  |
| general_log                     | OFF                                |
| general_log_file                | C:/xampp/mysql/data/mysql.log      |
| innodb_flush_log_at_trx_commit  | 1                                  |
| innodb_locks_unsafe_for_binlog  | OFF                                |
| innodb_log_buffer_size          | 8388608                            |
| innodb_log_file_size            | 5242880                            |
| innodb_log_files_in_group       | 2                                  |
| innodb_log_group_home_dir       | C:\xampp\mysql\data\               |
| innodb_mirrored_log_groups      | 1                                  |
| log                             | OFF                                |
| log_bin                         | OFF                                |
| log_bin_trust_function_creators | OFF                                |
| log_bin_trust_routine_creators  | OFF                                |
| log_error                       | C:\xampp\mysql\data\mysql.err      |
| log_output                      | FILE                               |
| log_queries_not_using_indexes   | OFF                                |
| log_slave_updates               | OFF                                |
| log_slow_queries                | OFF                                |
| log_warnings                    | 1                                  |
| max_binlog_cache_size           | 4294963200                         |
| max_binlog_size                 | 1073741824                         |
| max_relay_log_size              | 0                                  |
| relay_log                       |                                    |
| relay_log_index                 |                                    |
| relay_log_info_file             | relay-log.info                     |
| relay_log_purge                 | ON                                 |
| relay_log_space_limit           | 0                                  |
| slow_query_log                  | OFF                                |
| slow_query_log_file             | C:/xampp/mysql/data/mysql-slow.log |
| sql_log_bin                     | ON                                 |
| sql_log_off                     | OFF                                |
| sql_log_update                  | ON                                 |
| sync_binlog                     | 0                                  |
+---------------------------------+------------------------------------+
37 rows in set (0.00 sec)

回答by Shiplu Mokaddim

Enable general query log by the following query in mysql command line

在mysql命令行中通过以下查询启用通用查询日志

SET GLOBAL general_log = 'ON';

Now open C:/xampp/mysql/data/mysql.logand check query log

现在打开C:/xampp/mysql/data/mysql.log并检查查询日志

If it fails, open your my.cnffile. For windows its my.inifile and enable it there. Just make sure its in the [mysqld]section

如果失败,请打开您的my.cnf文件。对于 Windows,它的my.ini文件并在那里启用它。只要确保它在该[mysqld]部分

[mysqld]
general_log             = 1

Note: In xampp my.inifile can be either found in xampp\mysqlor in c:\windowsdirectory

注意:在 xamppmy.ini文件中可以xampp\mysqlc:\windows目录中或目录中找到

回答by AndreKR

回答by Jappy God

Its given on OFFICIAL MYSQL website.

它在官方 MYSQL 网站上给出。

SET GLOBAL general_log = 'ON';

You can also use custom path:

您还可以使用自定义路径:

[mysqld]
# Set Slow Query Log
long_query_time = 1
slow_query_log = 1
slow_query_log_file = "C:/slowquery.log"

#Set General Log
log = "C:/genquery.log"

回答by Chetter Hummin

Seems like the general query log is the file that you need. A good introduction to this is at http://dev.mysql.com/doc/refman/5.1/en/query-log.html

似乎一般查询日志是您需要的文件。对此的一个很好的介绍是在http://dev.mysql.com/doc/refman/5.1/en/query-log.html

回答by Bojan

For me, general_log didn't worked. But adding this to my.ini worked

对我来说,general_log 没有用。但是将此添加到 my.ini 工作

[mysqld]
log-output=FILE
slow_query_log = 1
slow_query_log_file = "d:/temp/developer.log"