Skip to content

Instantly share code, notes, and snippets.

@tphdev
Last active November 15, 2017 16:32
Show Gist options
  • Save tphdev/aa98f2b9093573e269e36cc375b1654b to your computer and use it in GitHub Desktop.
Save tphdev/aa98f2b9093573e269e36cc375b1654b to your computer and use it in GitHub Desktop.
Data Access Checklist

General Installation

[] Install MySQL-Server

sudo apt-get update
sudo apt-get install mysql-server

[] Start mysql server service

sudo service mysql stop
sudo usermod -d /var/lib/mysql mysql
sudo service mysql start 

[] MySQL User Config

(1) Create db password

  • put your own password inide the "......"
DBPW="......."

(2) Create db user

mysql -u root -p -e "CREATE USER '$USER'@'localhost' IDENTIFIED BY '$DBPW'";

(3) Grant 'root' privileges to user

mysql -u root -p -e "GRANT ALL ON *.* TO '$USER'@'localhost'";

[] Install knex globally

  • knex is what allows node to access our mysql db
npm install -g knex

[] Download MySQL Workbench

https://dev.mysql.com/downloads/workbench/


Project Config (each project)

[] Create DB

  • put the project's database name in "......"
DBNAME="......"
mysql -u $USER -p -e "CREATE DATABASE $DBNAME"

[] configure knexfile.js in project root

// Update with your config settings.

const devConfig = {
  client: 'mysql2',
  connection: {
    host : '127.0.0.1',
    port: '3306',
    user :      '---DB USERNAME---',
    password : '---DB USER PASSWORD---',
    database : '---DB NAME FOR PROJECT---'
  },
  migrations: {
    directory: './src/db/migrations'
  },
  seeds: {
    directory: './src/db/seeds'
  }
}

module.exports = {
  development: devConfig,
  production: {}
}

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