you can create a user by this command:
create user user@host;
example:
create user farzad@localhost;
and then you my set a password for the user. you can use this line to create a password for current user you are logged in:
set password = password('mynewpassword');
in the above command, the password() function converts the string parameter to a hashed password that will be used by mysql to authenticate users. if you use this line:
set password = 'mynewpassword';
then you have entered your string as your password and it is not a hashed value, so you will not be able to login again later. so do not forget to use the password() function.
to change password for another user, use this command:
set password for user@host = password('userpassword');
example:
set password for farzad@localhost = password('dalkXfda23423');
after creating a user and securing login with a password, you need to set permissions for the user. use the GRANT command to do this. general syntax is like this:
GRANT {PERMISSIONS} ON db.table TO user@host;
in this command, permissions are a comma separated list of permissions, like SELECT, INSERT, CREATE, DROP, DELETE. you can use ALL as a high level permission so the user can do most of the things.
db.table specifies the tables of a certain database where the user might do actions. so you can restrict a user to only a table of a database, or use the wildcard * to permit on all of tables or databases.
example:
GRANT ALL ON myDb.* to farzad@localhost;
if you have not created a user, or set a password, by using the grant command you can create the user, set the password for him, and grant permissions all at once. syntax is like this:
GRANT {PERMISSIONS} ON db.table to new_user@host IDENTIFIED BY 'userpassword';
example:
GRANT ALL ON myDb.* to [email protected] IDENTIFIED BY 'dalkXfda23423';