Posted By

apphp-snippets on 02/04/14


Tagged

mysql database create apphp


Versions (?)

Create a Database and Assign a User


 / Published in: MySQL
 

URL: http://www.apphp.com/index.php?snippet=mysql-create-database-and-assign-user

This is a very simple snippet about how to create a database 1st, a user and then assign some privileges to the user to allow him/her to perform some specific actions like insert, create, update, select etc.

  1. -- Create database, user and grant all privileges
  2. CREATE DATABASE database_name;
  3. CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';
  4. GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'localhost';
  5.  
  6. -- To grant just specific privileges, use the following format:
  7. GRANT SHOW DATABASES, SELECT, UPDATE, LOCK TABLES, RELOAD ON *.* TO 'user_name'@'localhost';

Report this snippet  

You need to login to post a comment.