majitux majitux -4 years ago 91
MySQL Question

Create an user account MySQL for Hive on Hadoop

I am trying to install Hive on Hadoop using MySQL as metastore. I am newbie with these technologies.
I was following this tutorial: https://www.youtube.com/watch?v=JJ5jFDxuA7A and one of the steps is create an user account for MySQL in this way:

CREATE USER 'hduserdb'@'localhost' IDENTIFIED BY 'hadoopdb';
GRANT ALL PRIVILEGES ON *.* TO 'hduserdb'@'localhost' WITH GRANT OPTION;
CREATE USER 'hduserdb'@'%' IDENTIFIED BY 'hadoopdb';
GRANT ALL PRIVILEGES ON *.* TO 'hduserdb'@'%' WITH GRANT OPTION;


I cannot understand why I need to do the last two lines. What does "%" mean in this context?
I tried to search information in the official documentation https://dev.mysql.com/doc/refman/5.7/en/account-names.html and I found this:

Account name syntax is 'user_name'@'host_name'.

An account name consisting only of a user name is equivalent to 'user_name'@'%'. For example, 'me' is equivalent to 'me'@'%'.


But I still do not understand :/ Are they equivalent? I mean, is the same write @'host_name' and @'%'? If so, why the tutorial use both?

I hope to be clear, please let me know if more information is needed. Thank you!

Answer Source

It is not necessary to use the four lines. I tested it. Also, I saw others tutorials and it uses only these lines:

CREATE USER 'hduserdb'@'%' IDENTIFIED BY 'hadoopdb';
GRANT ALL PRIVILEGES ON *.* TO 'hduserdb'@'%' WITH GRANT OPTION;

I hope it be helpful!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download