MySQL does not have a special command to create users instead it useses the same GRANT command that gives them privileges. The general form of this command is:
GRANT privileges [(columns)] ON item TO full_user_name [IDENTIFIED BY 'password'] [WITH GRANT OPTION];
| Privilege | Applies to | Description |
|---|---|---|
| SELECT | tables, columns | Allows user to select rows from tables |
| INSERT | tables, columns | Allows users to insert new rows into tables |
| UPDATE | tables, coulmns | Allows users to modify data in the existing tables |
| DELETE | tables | Allows users to delete existing table rows |
| INDEX | tables | Allows users to create and drop indexes on particular tables |
| ALTER | tables | Allows users to alter the structure of the existing tables |
| CREATE | databases, tables | Allows users to create new databases or tables. If a particular database or table is specified in the FRANT statement, they can only create that database or table, which means they have to DROP it first. |
| DROP | databases, tables | Allows users to delete databases or tables |
| Privilege | Description | Permitted commands |
|---|---|---|
| RELOAD | Allows an administrator to reload grant tables and flush privileges, hosts, logs, and tables | reload, refresh, flush privileges, flush hosts, flush logs, flush tables |
| SHUTDOWN | Allows an administrator to shutdown the server | shutdown |
| PROCESS | Allows an administrator to view server processes and kill them | show processlist, kill |
| FILE | Allows an administrator to read data from files on a server | load_file, load data infile |
| Privilege | Description |
|---|---|
| ALL | All privileges listed in the previous tables |
| USAGE | No privileges except a privilege to connect to the server. Usually used to create a user adn add more privileges later |
SET PASSWORD
FOR full_user_name = PASSWORD('newpassword');
GRANT USAGE ON *.* TO dummy@localhost IDENTIFIED BY 'test';
GRANT select, insert, update, delete, create, index, drop, alter
ON library.*
TO bob@localhost IDENTIFIED BY 'bobby17';
GRANT select
ON library.*
TO bob@'%';
SET PASSWORD FOR bob = password('bobby17');
GRANT ALL ON *.* TO admin@localhost IDENTIFIED BY 'new_admin_pass' WITH GRANT OPTION;
GRANT update, insert ON library.* TO bob@'%.marshall.edu';
GRANT select ON library.books TO danil@localhost;
GRANT update (checked) ON library.books TO danil@localhost;
REVOKE privileges [(columns)] ON item FROM full_user_name;or
REVOKE GRANT OPTION ON item FROM full_user_name;Please note that all changes in the privileges you made are not active until you FLUSH by using FLUSH PRIVILEGES command.
USE mysql;
UPDATE user
SET password = PASSWORD('new+password')
WHERE user = 'bob';
FLUSH PRIVILEGES;
You can find more information about this
here and more examples
here.