I often see in many MySQL tutorials that people use command IDENTIFIED BY 'password'
both during user creation and granting him privileges.
For example:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';
I tried using GRANT
without IDENTIFIED BY
and it works.
Can somebody explain me why it is used twice? Could there be other password for specific privileges?
Code below gives full access to all databases. Other commands mentioned in answers are work if you have the specific databases in the mysql server. Code below is works regardless of the state in which the server is in. Just login to the linux server -> type mysql and enter:
As grant self created user so, below line is enough for rights-
Note: Identify represents to your password what password you want to save for credential verification.
It's just an added security measure. You might have different passwords for the same user on different servers, for example in a shared host environment. If it's your own server and you and your colleagues are the only ones who use it then you don't need to identify the users you grant privileges to.
If you identify users then only the password you specify can be used with that user to perform those privileges.
GRANT
is meant for adding privileges to users. Confusingly, it also has the ability to create users and change their passwords. This functionality is deprecated and should not be used.If you use
GRANT
withIDENTIFIED
you can change the user's password:Also,
GRANT
may create the user if it does not exist:See https://dev.mysql.com/doc/refman/5.7/en/grant.html
In summary, use
CREATE
to create a user, and useGRANT
to add privileges: