Skip to content

Instantly share code, notes, and snippets.

@apphp
Created February 2, 2014 09:34
Show Gist options
  • Save apphp/8765344 to your computer and use it in GitHub Desktop.
Save apphp/8765344 to your computer and use it in GitHub Desktop.
Create a Database and Assign a 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.
Source: http://www.apphp.com/index.php?snippet=mysql-create-database-and-assign-user
*/
-- 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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment