Skip to content

Instantly share code, notes, and snippets.

@RobertoMachorro
Last active September 25, 2024 02:47
Show Gist options
  • Save RobertoMachorro/7d2ac7fa882aabd84fd6517e7242b208 to your computer and use it in GitHub Desktop.
Save RobertoMachorro/7d2ac7fa882aabd84fd6517e7242b208 to your computer and use it in GitHub Desktop.
Setup New Database with User

Setup New Database with User

MySQL

SHOW DATABASES;

CREATE DATABASE IF NOT EXISTS vapor_database
CHARACTER SET utf8
COLLATE utf8_unicode_ci;

CREATE USER 'vapor_username'@'localhost' IDENTIFIED BY 'vapor_password';
GRANT ALL PRIVILEGES ON vapor_database.* TO 'vapor_username'@'localhost';
FLUSH PRIVILEGES;

PostgreSQL

CREATE USER vapor_username;
ALTER USER vapor_username WITH PASSWORD 'vapor_password';
CREATE DATABASE vapor_database;
GRANT ALL PRIVILEGES ON DATABASE vapor_database TO vapor_username;
\c vapor_database
GRANT ALL ON SCHEMA public TO vapor_username; 

Prior to Postgres 15

CREATE USER vapor_username;
CREATE DATABASE vapor_database;
GRANT ALL PRIVILEGES ON DATABASE vapor_database TO vapor_username;
ALTER USER vapor_username WITH PASSWORD 'vapor_password';

MongoDB

use vapor_database
db.createUser({
	user: "vapor_username",
	pwd:  passwordPrompt(), // or cleartext password
	roles: [ { role: "readWrite", db: "vapor_database" } ]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment