Code Monkey home page Code Monkey logo

node-start's Introduction

node-start

##シンプルな掲示板をDBに保存する

準備:DBを用意するためにMySQLでDBを構築する

HomebrewでMySQLをインストール

brew install mysql

MySQLを起動

mysql.server start

MySQLにログイン

mysql -u root

パスワードは未入力でOK


「bulletin_board」というDBを作成

create database bulletin_board character set utf8;

DBが作成されているか確認

show databases;

「bulletin_board」DBに切り替え

use bulletin_board;

「boards」というテーブルを作成

CREATE TABLE `boards` (
  `board_id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL DEFAULT '',
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`board_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

「messages」というテーブルを作成

CREATE TABLE `messages` (
  `message_id` int(11) NOT NULL AUTO_INCREMENT,
  `board_id` int(11) NOT NULL,
  `message` text NOT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`message_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

作成したテーブルを確認

show tables;

「boards」デーブルの中身を確認

show columns from boards;

「messages」デーブルの中身を確認

show columns from messages;

アプリを立ち上げて確認

npm run dev

ブラウザでアクセス

localhost:3000



必要なければDBを削除

drop database bulletin_board;

MySQLからログアウト

exit;

MySQLを停止

mysql.server stop

node-start's People

Contributors

tongari avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.