2

In mysql's general log I see things like:

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

What is this "as anonymous on" thing even means? I log in as root@localhost. Am I still anonymous, or even "anonymous on"?

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  
0

1 Answer 1

4

After some major league Googling all over the planet, I think I found the answer.

From these posts I saw something interesting

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

My conjecture is the following: What follows as anonymous on is the currently connected database

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

The general log entry must say as anonymous on mysql

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

The general log entry must say as anonymous on test

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

The general log entry must say as anonymous on

Give it a Try !!!

UPDATE 2014-12-04 14:26 EST

Are you ready for this? I have an old post where someone has the source code with as anonymous on

log_warnings doesn't seem to work for aborted connections in MySQL 5.1

In the code from my 2-year-old post, as anonymous on is hardcoded !!!

Look at the code again

[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.

Please note the part of the code that references the database db ? db : (char*) "");. Either the db variable (the current database) points to a database name or an empty string.

The weird part about answering this question is that this is the second time I had to refer back to a post I myself wrote years ago. The first time was this: Does MySQL still handle indexes in this way?

UPDATE 2014-12-17 16:45 EST

Based on your last comment

But what exactly is your answer? That it doesn't matter what "as anonymous" mean? Otherwise, we've got yet to find out why thd->main_security_ctx.user is falsy.

In your question, you asked What is this "as anonymous on" thing even means? The answer I said was Either the db variable (the current database) points to a database name or an empty string. As for thd->main_security_ctx.user, thd->main_security_ctx.host_or_ip, that would be root@localhost. What comes after as anonymous on is the current DB. This is nothing left to figure out.

You then asked Am I still anonymous, or even "anonymous on"?. The answer would have to yes because you have been authenticated as a user of a DB Connection and your connection becomes an active thread like any other thread.

Any connection

  • DB connection from an authenticated user
  • system user (internal DB Connection for Replication)
  • Event Scheduler (DB Connection for Processing events)

are all equal threads. The general log does not differentiate one DB Connection from another. The code checks all connections the same way regardless of connections being internal or external.

If what my answer has stated still does not answer your question, there is really one thing you can do: Go to the MySQL Forums and post this question to the Developers. Since Konstantin Osipov was the developer who was responding to the Bug List and refers to this source code (bugs.mysql.com/bug.php?id=24761) that uses the expression as anonymous on in the general_log_print function, he would have to know the correct context and reason for using the expression as anonymous on.

UPDATE 2018-08-12 19:46 EDT

In ight of your conjecture, I went Googling around and found sample output from a general log:

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

Please look at both timestamp entries from the sample log:

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

as well as the original log entry from your question:

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

At these points in time, the user is not authenticated even though root@localhost appears. The comment for the code does support your conjecture. You now have the answer directly from the source code's author.

Thank you for accepting my posted answer (which lead to you finding the real answer)

7
  • 1
    Sort of yes, but it doesn't answer the question fully. What exactly "anonymous" means? Could there be anything but "anonymous"?
    – x-yuri
    Commented Dec 4, 2014 at 19:14
  • I have scoured the MySQL Documentation and cannot find anything on as anonymous on. If MySQL (really Oracle) does not document the context of this, no point in digging any further. If you are that curious, download the MySQL Source Code and grep for as anonymous on. If you find it, then it is hardcoded and can be nothing more. If it is not hardcoded, then there is some variable within the code that can change. It's sad that MySQL (eh, Oracle) does not document the meaning of this. Commented Dec 4, 2014 at 19:19
  • Almost there, what's left is to figure out why thd->main_security_ctx.user is falsy :)
    – x-yuri
    Commented Dec 5, 2014 at 7:15
  • Have I answered the question ? Commented Dec 17, 2014 at 18:24
  • 2
    It's not explicitly stated in your answer, but now judging from "Log the command before authentication checks", and thd->main_security_ctx.priv_user == thd->main_security_ctx.user ? (char*) "%s@%s on %s" : (char*) "%s@%s as anonymous on %s" I conjecture, that "as anonymous" means that at the moment the log entry is added, the user has yet to be authenticated. That was the only bit that was missing in your answer.
    – x-yuri
    Commented Aug 12, 2018 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.