AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 81092
Accepted
x-yuri
x-yuri
Asked: 2014-10-17 22:05:32 +0800 CST2014-10-17 22:05:32 +0800 CST 2014-10-17 22:05:32 +0800 CST

mysql的一般日志中的“匿名”是什么意思?

  • 772

在mysql的一般日志中,我看到如下内容:

141017  8:57:31     4 Connect   root@localhost as anonymous on

这个“匿名”是什么意思?我以root@localhost. 我仍然是匿名的,甚至是“匿名”吗?

UPD

$ systemctl stop mysqld
$ rm -f /var/lib/mysql/yuri.log
// enable general log in /etc/mysql/my.cnf
$ systemctl start mysqld
$ mysql -u root -p -BNe 'SELECT USER() HowYouAttemptedToLogin, CURRENT_USER() HowMySQLAllowedYouToLogin;'
Enter password:
root@localhost  root@localhost
$ mysql -u root -p -BNe 'SELECT host, user FROM mysql.user;'
Enter password: 
127.0.0.1   root
::1 root
localhost   hostname
localhost   root
$ cat /var/lib/mysql/yuri.log
/usr/bin/mysqld, Version: 10.0.14-MariaDB-log (MariaDB Server). started with:
Tcp port: 3306  Unix socket: /run/mysqld/mysqld.sock
Time                 Id Command    Argument
141204 19:03:19     3 Connect   UNKNOWN_USER@localhost as anonymous on 
            3 Connect   Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO)
141204 19:04:55     4 Connect   root@localhost as anonymous on 
            4 Query select @@version_comment limit 1
            4 Query SELECT USER() HowYouAttemptedToLogin, CURRENT_USER() HowMySQLAllowedYouToLogin
            4 Quit  
141204 19:05:47     5 Connect   root@localhost as anonymous on 
            5 Query select @@version_comment limit 1
            5 Query SELECT host, user FROM mysql.user
            5 Quit  
mysql log
  • 1 1 个回答
  • 8060 Views

1 个回答

  • Voted
  1. Best Answer
    RolandoMySQLDBA
    2014-12-05T10:22:04+08:002014-12-05T10:22:04+08:00

    在全球搜索了一些大联盟之后,我想我找到了答案。

    • http://dbaspot.com/mysql/70551-how-disable-any-logging-mysql.html
    • https://lists.drupal.org/pipermail/support/2014-June/025447.html

    从这些帖子中我看到了一些有趣的东西

    • 13679547 Connect @localhost as anonymous on test
    • 140612 12:33:07 3 Connect gk_admin at localhost as anonymous on dTEST_db

    我的猜想如下:下面as anonymous on是当前连接的数据库

    mysql -u root -Dmysql -p -BNe 'SELECT USER(),CURRENT_USER()'
    

    一般日志条目必须说as anonymous on mysql

    mysql -u root -Dtest -p -BNe 'SELECT USER(),CURRENT_USER()'
    

    一般日志条目必须说as anonymous on test

    mysql -u root -p -BNe 'SELECT USER(),CURRENT_USER()'
    

    一般日志条目必须说as anonymous on

    试试看 !!!

    更新 2014-12-04 14:26 EST

    你准备好了吗?我有一个旧帖子,其中有人有源代码as anonymous on

    log_warnings 似乎不适用于 MySQL 5.1 中的中止连接

    在我 2 岁的帖子中的代码中,as anonymous on是硬编码的!

    再看代码

    [29 Sep 2008 8:03] Konstantin Osipov
    OK, it was fixed differently:
          /*
            Log the command before authentication checks, so that the user can
            check the log for the tried login tried and also to detect
            break-in attempts.
          */
          general_log_print(thd, command,
                            (thd->main_security_ctx.priv_user ==
                             thd->main_security_ctx.user ?
                             (char*) "%s@%s on %s" :
                             (char*) "%s@%s as anonymous on %s"),
                            thd->main_security_ctx.user,
                            thd->main_security_ctx.host_or_ip,
                            db ? db : (char*) "");
    
    So, this is logged in the general log at least.
    
    I was reviewing a patch that added more logging,
    but I can't remember the worklog task number.
    

    请注意引用数据库的代码部分db ? db : (char*) "");。变量db(当前数据库)指向数据库名称或空字符串。

    回答这个问题的奇怪之处在于,这是我第二次不得不回顾我自己多年前写的一篇文章。第一次是这样的:MySQL 是否仍然以这种方式处理索引?

    更新 2014-12-17 16:45 EST

    根据您最后的评论

    但你的答案到底是什么?“匿名”是什么意思并不重要?否则,我们还没有弄清楚为什么 thd->main_security_ctx.user 是假的。

    在你的问题中,你问What is this "as anonymous on" thing even means?了我说的答案是Either the db variable (the current database) points to a database name or an empty string。至于thd->main_security_ctx.user, thd->main_security_ctx.host_or_ip,那就是root@localhost。接下来as anonymous是当前的数据库。这没什么好想明白的。

    你接着问Am I still anonymous, or even "anonymous on"?。答案必须是肯定的,因为您已被认证为数据库连接的用户,并且您的连接像任何其他线程一样成为活动线程。

    任何连接

    • 来自经过身份验证的用户的数据库连接
    • 系统用户(用于复制的内部数据库连接)
    • 事件调度程序(用于处理事件的数据库连接)

    都是相等的线程。通用日志不区分一个 DB 连接与另一个。无论连接是内部连接还是外部连接,代码都会以相同的方式检查所有连接。

    如果我的回答仍然不能回答您的问题,那么您确实可以做一件事:转到 MySQL 论坛并将此问题发布给开发人员。由于Konstantin Osipov开发人员正在响应 Bug 列表并引用了使用 中的表达式as anonymous on的源代码 (bugs.mysql.com/bug.php?id=24761),因此general_log_print function他必须知道正确的上下文和原因使用表达式as anonymous on。

    更新 2018-08-12 19:46 EDT

    根据您的猜想,我四处搜索并从一般日志中找到示例输出:

    131021 17:43:50    43 Connect root@localhost as anonymous on pnet_blog
           43 Init DB pnet_blog
           43 Query SELECT count(id) as total_posts FROM posts WHERE date_published is not null AND date_published <= '20131021144350'
           43 Query SELECT * FROM posts WHERE date_published is not null AND date_published <= '20131021144350' ORDER BY date_published DESC LIMIT 0,10
           44 Connect root@localhost as anonymous on pnet_blog
           44 Query SELECT id, title, impressions FROM tips WHERE date_published IS NOT NULL AND date_published <= '20131021144350' ORDER BY date_published DESC LIMIT 0, 10
           44 Quit
           43 Quit
    131021 17:44:28    45 Connect root@localhost as anonymous on pnet_blog
           45 Init DB pnet_blog
           45 Query SELECT * FROM posts WHERE url='how-and-when-to-enable-mysql-logs'
           45 Query UPDATE posts SET impressions=impressions+1 WHERE id='41'
           45 Query SELECT url, post_title FROM posts WHERE date_published IS NOT NULL AND date_published < '20131020150000' ORDER BY date_published DESC LIMIT 0,1
           45 Query SELECT url, post_title FROM posts WHERE date_published IS NOT NULL AND date_published > '20131020150000' ORDER BY date_published ASC LIMIT 0,1
           45 Query SELECT * FROM posts WHERE date_published is not null AND date_published <= '20131021144428' AND date_published >= '20130421144428' ORDER BY impressions DESC LIMIT 0,10
           46 Connect root@localhost as anonymous on pnet_blog
           46 Query SELECT id, title, impressions FROM tips WHERE date_published IS NOT NULL AND date_published <= '20131021144428' ORDER BY date_published DESC LIMIT 0, 10
           46 Quit
           45 Quit
    

    请查看示例日志中的两个时间戳条目:

    131021 17:43:50    43 Connect root@localhost as anonymous on pnet_blog
    131021 17:44:28    45 Connect root@localhost as anonymous on pnet_blog
    

    以及您问题的原始日志条目:

    141017  8:57:31     4 Connect   root@localhost as anonymous on
    

    在这些时间点,即使 root@localhost出现,用户也没有经过身份验证。该代码的注释确实支持您的猜想。您现在可以直接从源代码的作者那里得到答案。

    感谢您接受我发布的答案(这导致您找到真正的答案)

    • 4

相关问题

  • 是否有任何 MySQL 基准测试工具?[关闭]

  • 我在哪里可以找到mysql慢日志?

  • 如何优化大型数据库的 mysqldump?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

  • 组如何跟踪数据库架构更改?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve