Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grant command doesn't work in mysql

Tags:

mysql

I've logged in as root and typed the below command

GRANT ALL PRIVILEGES ON *.* TO 'hive'@'master'  WITH GRANT OPTION;

the result is

Query OK, 0 rows affected, 1 warning (0.00 sec)

the warning message is

Warning | 1285 | MySQL is started in --skip-name-resolve mode; you must restart it without this switch for this grant to work

and then I check the grants for user 'hive'

mysql> show grants for hive;
+-----------------------------------------------------------------------------------------------------+
| Grants for hive@%                                                                                   |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'hive'@'%' IDENTIFIED BY PASSWORD '*4DF1D66463C18D44E3B001A8FB1BBFBEA13E27FC' |
+-----------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

and I tried

show grants for 'hive'@'master' 
ERROR 1141 (42000): There is no such grant defined for user 'hive' on host 'master'

why doesn't grant command work here?


I disabled skip-name-resolv in /etc/my.cnf and it works. http://mysql-forum.ch/archive/index.php?thread-5.html I think the warning is mainly caused by using the host name 'master' instead of an ip address.

But is it appropriate to set skip-name-resolv disabled in /etc/my.cnf or is there any other choice?

like image 338
April Avatar asked Oct 27 '25 10:10

April


1 Answers

Nothing wrong with the grant statement there, you are using the show grants statement incorrectly. As MySQL documentation on show grants says:

To name the account, use the same format as for the GRANT statement; for example, 'jeffrey'@'localhost'. If you specify only the user name part of the account name, a host name part of '%' is used.

'hive'@'master' and 'hive'@'%' users are different. To show 'hive'@'master' user's grants, use the full user account name in the show grants statement.

like image 134
Shadow Avatar answered Oct 30 '25 00:10

Shadow