Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Last active June 8, 2020 00:40
Show Gist options
  • Save ryanburnette/432520f4cb659d36e195bb9febf2ddd4 to your computer and use it in GitHub Desktop.
Save ryanburnette/432520f4cb659d36e195bb9febf2ddd4 to your computer and use it in GitHub Desktop.
configure MySQL database and user https://ryanburnette.com/blog/mysql
CREATE DATABASE IF NOT EXISTS databasename;
CREATE USER IF NOT EXISTS 'username'@'localhost' IDENTIFIED BY '_not_password_';
ALTER USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
@coolaj86
Copy link

coolaj86 commented May 7, 2020

Here's my slight variation for idempotent setup, and using mariadb:

setup.sql:

CREATE DATABASE IF NOT EXISTS databasename;
CREATE USER IF NOT EXISTS 'username'@'localhost' IDENTIFIED BY '_not_password_';
ALTER USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
mysql -u root < setup.sql
mysql -u username -p
mysql://username:password@localhost/databasename

Also (note to self), what I had to do to install MariaDB 10.4.

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu $(lsb_release -cs) main"
sudo apt update
sudo apt -y install mariadb-server mariadb-client
sudo mysql_secure_installation

@ryanburnette
Copy link
Author

@solderjs Thanks for the edits. Looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment