Skip to content

Instantly share code, notes, and snippets.

@franzwong
Last active April 14, 2018 15:49
Show Gist options
  • Save franzwong/ad1582cb2e3417860f5d2bf51a429a24 to your computer and use it in GitHub Desktop.
Save franzwong/ad1582cb2e3417860f5d2bf51a429a24 to your computer and use it in GitHub Desktop.
Setup local development environment with docker

Setup local development environment with docker

MySQL

Start MySQL docker

docker run --name local-mysql -d \
  -v <local data dir>:/var/lib/mysql \
  -e MYSQL_ROOT_PASSWORD=<password> \
  -p 3306:3306 \
  mysql:5.7.21

Connect to docker with MySQL client

docker run -it --link local-mysql:mysql \
  --rm mysql:5.7.21 \
  sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

Create database

CREATE DATABASE <database>;

Select database

USE <database>;

Show all tables

SHOW TABLES;

Create table

CREATE TABLE items (
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
  type INT NOT NULL,
  PRIMARY KEY (id)
);

Show table schema

DESCRIBE items;

Create user with limited privileges

GRANT SELECT, INSERT, UPDATE, DELETE ON <database>.* TO '<user name>'@'%' IDENTIFIED BY '<password>';

Insert record

INSERT INTO items (type) VALUES (100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment