Sandra Schlichting
Sandra Schlichting

Reputation: 26046

How to create MySQL user with limited privileges?

I would like to create a user called webapp that can access a database called webdb with the following privileges

Select, Insert, Update, Delete, Create, Drop, References, Index, Alter, Lock_Tables 

I created the database like so

mysql -u root -p -e 'create database webdb'

How is such a user created from the commandline?

Upvotes: 7

Views: 8047

Answers (1)

Devart
Devart

Reputation: 122042

Something like this:

CREATE USER 'new_user'@'host_name' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE, ALTER, CREATE, DROP, INDEX, LOCK TABLES, REFERENCES
  ON webdb.* TO 'new_user'@'host_name';

Second statement will grant privileges on webdb database.

Upvotes: 13

Related Questions