0

Using mySQL, the database keeps thinking I'm ''@'localhost' even though I've already signed in as '(username)'@'localhost'.

It gets stranger:

I'm allowed to create databases called 'test', 'test_db', etc. and tables within them, but if I try to create a database with any other name, I get a:

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'someDB'

I've already logged in as 'username'@'localhost'. Why does it think I'm ''@'localhost'?

Perhaps this is relevant?

mysql> select user(), current_user();
+------------------+----------------+
| user()           | current_user() |
+------------------+----------------+
|username@localhost| @localhost     |
+------------------+----------------+
1 row in set (0.00 sec)

This becomes increasingly annoying as I try to use SQL within Java. It seems as soon as I log in it forgets that I've logged in as (username).

I've read somewhat about how usernames and login names are different? Why is user() different from current_user()? I think these might be clues... Any advice, friends?

mnekmonic
  • 1
  • 1
  • What's your command line for starting up the mysql monitor? – Marc B Jul 09 '14 at 21:53
  • `-bash:(server):~ 254 $ mysql -u (username) -p Enter password: Welcome to the MySQL monitor.` – mnekmonic Jul 09 '14 at 21:55
  • 2
    If the anonymous user for localhost exists then it will match every username first. See http://stackoverflow.com/questions/1412339/cannot-log-in-with-created-user-in-mysql – VMai Jul 09 '14 at 21:58
  • @MarcB the mysql startup command was in my previous comment. – mnekmonic Jul 09 '14 at 22:01
  • @VMai Interesting, thank you. However, I do not have root privileges to be able to dump the mysql database or delete the anonymous user. Any other suggestions? – mnekmonic Jul 09 '14 at 22:04
  • As long as the anonymous user exists, that's the one that will be matched when you connect. You can try bypassing `'localhost'` anonymous user by specifying TCP protocol. Try adding `-h 127.0.0.1` option to the `mysql -u ...` command. (It's possible you will also encounter another anonymous user, but that will be a different user `''@'127.0.0.1'`. (A database user with sufficient privileges can `DROP` those annoying anonymous users.) – spencer7593 Jul 09 '14 at 22:09
  • http://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw has better explanation and hints, what you can try. But you could try the dba admin to remove this user. – VMai Jul 09 '14 at 22:10
  • @spencer7593 Thanks, but the `-h` tag didn't work. I suppose I'll just ask my sysadmin to drop the anon user. I'm shocked that this exists, though. Wouldn't it be theoretically causing problems for all default mySQL installs? – mnekmonic Jul 09 '14 at 22:21
  • @VMai 's comment should be the accepted answer, would you mind adding it as an answer? – 4levels Sep 10 '19 at 08:23

0 Answers0