如何在MySQL中查看日志文件? [英] How to see log files in MySQL?
问题描述
我已经阅读到Mysql服务器创建了一个日志文件,其中记录了所有活动-例如何时以及执行什么查询.
I've read that Mysql server creates a log file where it keeps a record of all activities - like when and what queries execute.
有人可以告诉我它在系统中的什么位置吗?我怎么读?
Can anybody tell me where it exists in my system? How can I read it?
基本上,我需要使用不同的输入(两个日期之间的备份)来备份数据库,所以我认为我需要在这里使用日志文件,这就是为什么我想要这样做...
Basically, I need to back up the database with different input [backup between two dates] so I think I need to use log file here, that's why I want to do it...
我认为必须以某种方式保护此日志的安全,因为可能会记录诸如用户名和密码之类的敏感信息[如果有任何查询需要此信息];这样可以保证它的安全性,使其不容易被看到吗?
I think this log must be secured somehow because sensitive information such as usernames and password may be logged [if any query require this]; so may it be secured, not easily able to be seen?
我具有root访问系统的权限,如何查看日志?
I have root access to the system, how can I see the log?
当我尝试打开/var/log/mysql.log时,它是空的.
When I try to open /var/log/mysql.log it is empty.
这是我的配置文件:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
log = /var/log/mysql/mysql.log
binlog-do-db=zero
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
general_log_file = /var/log/mysql/mysql.log
general_log = 1
推荐答案
此处是启用它们的简单方法.在mysql中,我们通常需要查看3条日志,这在任何项目开发过程中都是最需要的.
Here is a simple way to enable them. In mysql we need to see often 3 logs which are mostly needed during any project development.
-
The Error Log
.它包含有关在以下情况下发生的错误的信息: 服务器正在运行(服务器也正在启动和停止)
The Error Log
. It contains information about errors that occur while the server is running (also server start and stop)
The General Query Log
.这是什么是mysqld的一般记录
做(连接,断开连接,查询)
The General Query Log
. This is a general record of what mysqld is
doing (connect, disconnect, queries)
The Slow Query Log
.它由慢速" SQL语句(如
用其名称表示).
The Slow Query Log
. Ιt consists of "slow" SQL statements (as
indicated by its name).
默认情况下,MYSQL中未启用任何日志文件.所有错误将显示在系统日志(/var/log/syslog
)中.
By default no log files are enabled in MYSQL. All errors will be shown in the syslog (/var/log/syslog
).
要启用它们,只需执行以下步骤:
To Enable them just follow below steps:
步骤1::转到此文件(/etc/mysql/conf.d/mysqld_safe_syslog.cnf ),然后删除或注释这些行.
step1: Go to this file (/etc/mysql/conf.d/mysqld_safe_syslog.cnf) and remove or comment those line.
步骤2::转到mysql conf文件(/etc/mysql/my.cnf
)并添加以下几行
step2: Go to mysql conf file (/etc/mysql/my.cnf
) and add following lines
要启用错误日志,请添加以下内容
[mysqld_safe]
log_error=/var/log/mysql/mysql_error.log
[mysqld]
log_error=/var/log/mysql/mysql_error.log
要启用常规查询日志,请添加以下
general_log_file = /var/log/mysql/mysql.log
general_log = 1
要启用慢速查询日志,请添加以下内容
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
第3步:保存文件并使用以下命令重新启动mysql
step3: save the file and restart mysql using following commands
service mysql restart
要在运行时启用日志,请登录mysql客户端(mysql -u root -p
)并输入:
To enable logs at runtime, login to mysql client (mysql -u root -p
) and give:
SET GLOBAL general_log = 'ON';
SET GLOBAL slow_query_log = 'ON';
最后,我想在这里提及的一件事是我是从博客中读到的.谢谢.它对我有用.
Finally one thing I would like to mention here is I read this from a blog. Thanks. It works for me.
点击此处以访问博客
这篇关于如何在MySQL中查看日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!