记录MySQL交互式查询 [英] Logging MySQL interactive queries

查看:161
本文介绍了记录MySQL交互式查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个人直接在一些系统中进行一些数据库查询。



我想将一个安全的系统日志服务器以交互方式/手动完成所有查询,或者失败的是,使用 mysql 二进制客户端完成的所有查询。



我正在使用Debian Jessie, Oracle MySQL 5.6.31



如何实现?

解决方案

从MySQL 5.7开始, mysql 命令接受--syslog选项。所以我将一个测试系统升级到MySQL 5.7,它的工作原理。
我将从 mysql mysql --syslog


中的别名

MySQL 5.7参考手册 - mysql记录


syslog日志记录特征



如果--syslog选项给出,mysql将交互式语句
写入系统日志记录工具。消息记录具有以下
特征。



记录发生在信息级别。这对应于Unix / Linux系统日志功能上的syslog的
LOG_INFO优先级和Windows事件日志的
EVENTLOG_INFORMATION_TYPE。请咨询您的
系统文档以配置您的记录功能。



邮件大小限制为1024字节。



消息由标识符MysqlClient跟着这些
值组成:



SYSTEM_USER



系统用户名(登录名)或 - 如果用户未知。



MYSQL_USER



MySQL用户名称(用--user选项指定)或 - 如果
用户未知。



CONNECTION_ID:



客户端连接标识符。这与会话中的
CONNECTION_ID()函数值相同。



DB_SERVER



服务器主机或 - 如果主机未知。



DB



默认数据库或 - if没有选择数据库。



QUERY



记录语句的文本。



以下是使用--syslog在Linux上生成的输出示例。此
输出格式化为可读性;每个记录的消息实际上是
需要一行。



3月7日12:39:25 myhost MysqlClient [20824]:SYSTEM_USER:'oscar',
MYSQL_USER:'my_oscar',CONNECTION_ID:23,DB_SERVER:'127.0.0.1',
DB:' - ',QUERY:'USE test;'3月7日12:39:28 myhost MysqlClient [20824]
SYSTEM_USER:'oscar',MYSQL_USER:'my_oscar',CONNECTION_ID:23,

DB_SERVER:'127.0.0.1',DB:'test',QUERY:'SHOW TABLES;'



I have several people doing some database queries directly into some systems.

I would like to log to a secure syslog server all the queries done interactively/by hand, or failing that, all the queries done by using the mysql binary client.

I am using Debian Jessie, and Oracle MySQL 5.6.31

How could I achieve that?

解决方案

Starting in MySQL 5.7, the mysql command accepts the --syslog option. So I upgraded a test system to MySQL 5.7, and it works. I will make an alias from mysql to mysql --syslog

From MySQL 5.7 Reference Manual - mysql Logging

syslog Logging Characteristics

If the --syslog option is given, mysql writes interactive statements to the system logging facility. Message logging has the following characteristics.

Logging occurs at the "information" level. This corresponds to the LOG_INFO priority for syslog on Unix/Linux syslog capability and to EVENTLOG_INFORMATION_TYPE for the Windows Event Log. Consult your system documentation for configuration of your logging capability.

Message size is limited to 1024 bytes.

Messages consist of the identifier MysqlClient followed by these values:

SYSTEM_USER

The system user name (login name) or -- if the user is unknown.

MYSQL_USER

The MySQL user name (specified with the --user option) or -- if the user is unknown.

CONNECTION_ID:

The client connection identifier. This is the same as the CONNECTION_ID() function value within the session.

DB_SERVER

The server host or -- if the host is unknown.

DB

The default database or -- if no database has been selected.

QUERY

The text of the logged statement.

Here is a sample of output generated on Linux by using --syslog. This output is formatted for readability; each logged message actually takes a single line.

Mar 7 12:39:25 myhost MysqlClient[20824]: SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23, DB_SERVER:'127.0.0.1', DB:'--', QUERY:'USE test;' Mar 7 12:39:28 myhost MysqlClient[20824]: SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,
DB_SERVER:'127.0.0.1', DB:'test', QUERY:'SHOW TABLES;'

这篇关于记录MySQL交互式查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆