Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create MySQL user with limited privileges?

Tags:

mysql

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?

like image 541
Sandra Schlichting Avatar asked Feb 07 '12 10:02

Sandra Schlichting


People also ask

How do I set MySQL privileges?

To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';


1 Answers

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.

like image 148
Devart Avatar answered Sep 28 '22 09:09

Devart