SQL: MySQL + USERS + MAC

when installing mysql for the very first time, you will need to create a root password in order to enter the mysql database:

mysqladmin -u ROOT_USER_NAME -p ROOT_PASSWORD

sign into mysql using the following command:

mysql --user=ROOT_USER_NAME --password=ROOT_PASSWORD

once in, you want to first navigate to the mysql database:

use mysql;

you can now insert more users to your liking by using the following commands:

create user 'SUB_USER_NAME'@'LOCALHOST';

set that person's password by using:

set password for 'SUB_USER_NAME'@'LOCALHOST' = PASSWORD('SUB_USER_PASSWORD');

now to give all permissions for the new user...

grant all privileges on *.* to 'SUB_USER_NAME'@'LOCALHOST' IDENTIFIED BY 'SUB_USER_PASSWORD' WITH GRANT OPTION;

or if you want to just grant certain privileges (in this case, SELECT):

grant SELECT on *.* to 'SUB_USER_NAME'@'LOCALHOST' IDENTIFIED BY 'SUB_USER_PASSWORD';

if you made a mistake, you can revoke the privileges by doing this:

revoke all privileges, grant option from 'SUB_USER_NAME'@'LOCALHOST';

NOTE:
1. *.* means you are granting permission to SELECT on all databases. Alternatively you could also specify a specific database, ie. mysql.user
2. GRANT OPTION is a special command that allows the SUB_USER to grant that same permission to other users

No comments: