Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Latest commit

 

History

History

mysql-server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

MySQL Server

An express-server but with a mysql database.

Install

First, get the example:

git clone git@github.com:cmda-be/course-17-18.git
cd course-17-18/examples/mysql-server
npm install

Then, log into mysql:

mysql -u your-username -p
# Enter your password

…and run the following SQL to set up a database and populate a movies table:

CREATE DATABASE IF NOT EXISTS mymoviewebsite;
USE mymoviewebsite;
CREATE TABLE IF NOT EXISTS movies (
  id INT NOT NULL AUTO_INCREMENT,
  cover TEXT CHARACTER SET utf8,
  title TEXT CHARACTER SET utf8,
  description TEXT CHARACTER SET utf8,
  plot TEXT CHARACTER SET utf8,
  PRIMARY KEY (id)
);
-- Add some movies like so:
INSERT INTO movies (title, plot, description) VALUES (
  'Evil Dead',
  'Five friends travel to a cabin in …',
  'Five friends head to a remote cabin, …'
);
INSERT INTO movies (title, plot, description) VALUES (
  'The Shawshank Redemption',
  'Two imprisoned men bond over a …',
  'Andy Dufresne is a young and …'
);

Now, add a .env file with the following info (replacing the values with actual values):

DB_HOST=localhost
DB_USER=myusername
DB_NAME=mydatabase
DB_PASSWORD=mypassword

Finally, start the server with:

npm start

Changes

The following commits show how this example was created:

License

MIT © Titus Wormer