Return to Snippet

Revision: 65883
at February 4, 2014 21:21 by apphp-snippets


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

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

Initial Description
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.

Initial Title
Create a Database and Assign a User

Initial Tags
mysql, database

Initial Language
MySQL