3

Today I encountered an issue that I can't find my database created by a ROR project from mysql cli. After some spike, It turns out that I didn't login as root, I just use mysql without any argument. So my question is if you login with a bare 'mysql' command, who you are login as and what is the permission you have? By the way, the mysql version is 5.5 .

Reply for marked as duplicate:

Actually, I don't believe this is dup with MySQL Utilities - ~/.my.cnf option file; I checked my env, I don't have a default config file and I didn't store any password anywhere. My question is who I'm login as if use a bare mysql command. One clue is when I try to query mysql.user, I got message below. So I think I'm login as @localhost, but where this name come from?

Blockquote mysql> SELECT host, user, password from mysql.user; ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user' mysql>

Community
  • 1
  • 1
hsc
  • 1,226
  • 11
  • 24

1 Answers1

1

Only the users listed in mysql.user table can login.

SELECT host, user, password from mysql.user; -- MySQL before 5.7
SELECT host, user, authentication_string from mysql.user; -- MySQL 5.7 +

For the CLI access, the mysql config file can have your password already typed in. The path and name of that that file file varies in different operating systems and versions of database you use.

Accessing MySQL without password may mean:

  • Your user account does not have the password at all.
  • Or, you do not need to type in the password, because your config file contains it already. (This may be your way, in this problem.)

Both the options may be unsafe to use.

Also, see in:

Community
  • 1
  • 1
Bimal Poudel
  • 1,214
  • 2
  • 18
  • 41
  • Thanks, I found that I was login as "@localhost", But it was not my login user name, do you know what is the default username mysql use? – hsc Oct 10 '16 at 07:23