How to Query Database User Log Information at a Specific Point in Time

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何查询在某个时间点登录的数据库用户日志信息

| username: xiaoxiaozuofang

How to query the database user log information at a specific point in time

| username: ealam_小羽 | Original post link

The General Log should be available, but if this log is enabled, it records all SQL statements, making the log quite large. It seems like this requirement is somewhat similar to auditing, and it appears that the enterprise edition has auditing features.

| username: redgame | Original post link

There is no direct way to check. You can enable the slow log and grep “Login” from /path/to/slow.log.

| username: hey-hoho | Original post link

The community edition probably doesn’t have this feature. Maybe the auditing feature in the enterprise edition can achieve this, but I haven’t used it~

| username: zhanggame1 | Original post link

This is a database auditing feature, available only in the enterprise edition. You can also use other auditing software or out-of-band auditing.

| username: 我是咖啡哥 | Original post link

The community edition doesn’t work.
I tested enabling the general log

set global tidb_general_log=ON;

The tidb.log only records information like this:

[2023/07/22 23:03:10.298 +08:00] [INFO] [session.go:3878] [GENERAL_LOG] [conn=7845668574088659355] [user=root@] [schemaVersion=14934] [txnStartTS=0] [forUpdateTS=0] [isReadConsistency=false] [currentDB=] [isPessimistic=false] [sessionTxnMode=PESSIMISTIC] [sql="select @@version_comment limit 1"]
[2023/07/22 23:03:10.301 +08:00] [INFO] [session.go:3878] [GENERAL_LOG] [conn=7845668574088659355] [user=root@] [schemaVersion=14934] [txnStartTS=0] [forUpdateTS=0] [isReadConsistency=false] [currentDB=] [isPessimistic=false] [sessionTxnMode=PESSIMISTIC] [sql="select USER()"]

You can only see the SQL, but not the user information. It’s not useful.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.