2,187
edits
(Initial creation - content from MySQL page (now category)) |
(→Create Users and Grant/Revoke Privileges: Updated add new user) |
||
Line 1: | Line 1: | ||
== Create Users and Grant/Revoke Privileges == | == Create Users and Grant/Revoke Privileges == | ||
To create a new user you need to specify the username, the location/IP address it will be connecting from (use <code>%</code> for any location), and their password | |||
<source lang="mysql"> | <source lang="mysql"> CREATE USER '<user>'@'localhost' identified by '<password>';</source> | ||
You can then give permissions to that user | |||
<source lang="mysql"> GRANT ALL ON <dayabase>.* TO '<user>'@'localhost';</source> | |||
Depending on the version of MySQL running you can do this in one command (note that the <code>WITH GRANT OPTION</code> allows the user to create more users and/or grant privileges to users). | |||
<source lang="mysql"> GRANT ALL PRIVILEGES on <database>.* to '<user>'@'%' identified by '<password>' WITH GRANT OPTION; </source> | <source lang="mysql"> GRANT ALL PRIVILEGES on <database>.* to '<user>'@'%' identified by '<password>' WITH GRANT OPTION; </source> | ||
Line 17: | Line 20: | ||
To remove/revoke a privilege from an existing user ''web-user''; | To remove/revoke a privilege from an existing user ''web-user''; | ||
<source lang="mysql"> REVOKE SELECT ON webdb.* FROM 'web-user'@'localhost';</source> | <source lang="mysql"> REVOKE SELECT ON webdb.* FROM 'web-user'@'localhost';</source> | ||
After making any changes to user privilages, you need to flush them to ensure they're applied... | |||
<source lang="mysql"> FLUSH PRIVILEGES; </source> | |||
== Delete Users == | == Delete Users == |