Create a Database and Assign a User


/ Published in: MySQL
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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';

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.