Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
Last active December 22, 2015 11:05
Show Gist options
  • Select an option

  • Save PieterScheffers/06d56bbe9e3dc723fe71 to your computer and use it in GitHub Desktop.

Select an option

Save PieterScheffers/06d56bbe9e3dc723fe71 to your computer and use it in GitHub Desktop.
MySQL create database
# https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql
# https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial
# Create a new database
CREATE DATABASE somedatabase
# Create a new user
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
# Delete a user
DROP USER ‘demo’@‘localhost’;
# Grant all privileges on user (ROOT user)
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
# ALL PRIVILEGES all access
# CREATE create new tables or databases
# DROP delete tables or databases
# DELETE delete rows from tables
# INSERT insert rows into tables
# SELECT select command to read through databases
# UPDATE update table rows
# GRANT OPTION grant or remove other users' privileges
# Give user a permission
# GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
# Withdraw a permission for a user
# REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;
# activate new privileges
FLUSH PRIVILEGES;
# Show all grants for user
SHOW GRANTS FOR 'someuser'@'localhost';
################## Create simple database user ##########################
# Create database
# Create user
# Give user all privileges but grant ability on all database tables
# flush privileges
CREATE DATABASE somedatabase
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
GRANT CREATE ON somedatabase.* TO ‘someuser’@'localhost’;
GRANT DROP ON somedatabase.* TO ‘someuser’@'localhost’;
GRANT DELETE ON somedatabase.* TO ‘someuser’@'localhost’;
GRANT INSERT ON somedatabase.* TO ‘someuser’@'localhost’;
GRANT SELECT ON somedatabase.* TO ‘someuser’@'localhost’;
GRANT UPDATE ON somedatabase.* TO ‘someuser’@'localhost’;
FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment