Skip to content

Instantly share code, notes, and snippets.

@floscher
Created June 7, 2020 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floscher/dcbb53c16511b3a345ab027140e52e2f to your computer and use it in GitHub Desktop.
Save floscher/dcbb53c16511b3a345ab027140e52e2f to your computer and use it in GitHub Desktop.

MySQL

Start MySQL client as root user:

$ sudo mysql -u root

See existing users:

> SELECT User, Host from mysql.user;

Create new database and user:

> CREATE DATABASE mydb;
> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
> GRANT ALL PRIVILEGES ON `mydb`.* TO 'myuser'@'localhost';

PostgreSQL

Start PostgreSQL client as postgres user:

$ sudo -u postgres psql

Create user and database:

# CREATE DATABASE mydb;
# CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypass';
# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment