코딩공부/MySQL

Maria DB ( + node.js와 연결하여 화면에 출력하기)

뉼👩🏻‍💻 2022. 11. 21. 01:19
728x90
반응형
SMALL

 

Mariadb는 mysql 기반의 오픈소스 DB이다

 

w3s 에 기초부터 잘 나와있다

https://www.w3schools.com/nodejs/nodejs_mysql.asp

 

Node.js MySQL

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

 

 

Download 

 

 

operating System에서 맥 os가 없어서 찾아봤더니 home brew로 설치 가능했다 

https://mariadb.com/kb/ko/installing-mariadb-on-macos-using-homebrew/

 

Homebrew로 macOS에 MariaDB Server 설치

Homebrew 패키지 매니저를 이용해서 MariaDB Server를 macOS (이전 Mac OS X) 설치할 수 있습니다. MariaDB Server는 미리 컴파일된 Homebrew "bottle" 패키지로 이용 가능하며, 소스 빌드가 필요 없어 시간을 절약해

mariadb.com

 

 

설치 완료! 

 

 

 

설치 한 뒤에 상태를 확인하고 싶어서 

mysql.server status

를 입력했지만 나오지 않고 ... 뭘해도 나오지 않았따

 

 

구글링해보다가 아래의 방법으로 성공

 

 

https://okky.kr/articles/615253

 

OKKY - All That Developer

OKKY는 국내 최대 개발자 지식공유 플랫폼입니다. 개발자에게 필요한 기술 Q&A, 아티클, 커리어, 네트워킹, 취업, IT행사를 지원합니다

okky.kr

 

*DB 생성하기 

- 분명히 명령어가 맞는데 대체 왜 안나오고 자꾸 저노무 화살표만 뜨는지 찾질 못했음 

 

딴 명령어를 쳐봐도 난 테이블표시라고는 볼 수가 없고 ㅇㅁㄴ라ㅓㅁㅇ라

 

알고보니 쿼리문 끝에 ; 를 안붙여서 안나왔던거였음(이런건 말 좀 해줘라 ....) 

 

 

* db생성하고 계정 생성하고 권한부여 

- 아래의 블로그 글에 나와있는 모든 에러를 다 접했따 ^^ 하하

(1. 오타확인 제대로하기, 2. 끝에 ';' 빼먹지 말고 잘 쓰기 )

https://light-tree.tistory.com/247

 

macOS에서 MariaDB db생성, 계정생성, 권한부여

mariadb를 실행합니다. root@MacBookAir var % mariadb Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.7.3-MariaDB Homebrew Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others

light-tree.tistory.com

 

 

https://reddb.tistory.com/108

 

[MariaDB] 마리아DB SQL 쿼리 기본 - SELECT (MySQL)

[MariaDB] 마리아DB SQL 쿼리 기본 - SELECT (MySQL) DB목록 조회 SHOW DATABASES; DB선택 USE DB명; 선택된 DB에 존재하는 테이블 정보 조회 SHOW TABLE STATUS; -- 테이블 이름만 간단히 볼 때는 SHOW TABLES; 테이블 조회(S

reddb.tistory.com

쿼리문은 mysql과 똑같다 

 

 

길고 긴 방황끝에 연결은 무사히 했따 ... 진짜 기억력 무엇 .. 

workbench와 연결은 했지만 왜 연결이 되었는지는 모르겟다 하하 

 

 

* node.js 의 express를 활용하여 mariadb에 있는 내용 화면에 뿌려주기 

const express = require("express");

const app = express();

const server = app.listen(3000, () => {
  console.log("start server : localhost :3000");
});

app.set("views", __dirname + "/views");

//ejs : embedded javascript templates
app.set("view engine", "ejs");
app.engine("html", require("ejs").renderFile);

app.get("/", function (req, res) {
  // res.send("hello world");
  res.render("index.html");
});

app.get("/about", function (req, res) {
  // res.send("about page");
  res.render("about.html");
});

app.get("/db", function (req, res) {
  pool.getConnection(function (err, connection) {
    if (err) throw err; // not connected!

    // Use the connection
    connection.query("SELECT * FROM bobjip", function (error, results, fields) {
      res.send(JSON.stringify(results));
      console.log("results", results);
      // When done with the connection, release it.
      connection.release();

      // Handle error after the release.
      if (error) throw error;

      // Don't use the connection here, it has been returned to the pool.
    });
  });
});

var mysql = require("mysql");
var pool = mysql.createPool({
  connectionLimit: 10,
  host: "127.0.0.1",
  user: "root",
  password: ###",
  database: "##_db",
});

 

 

 

참고자료

https://mariadb.com/kb/ko/installing-mariadb-on-macos-using-homebrew/

 

Homebrew로 macOS에 MariaDB Server 설치

Homebrew 패키지 매니저를 이용해서 MariaDB Server를 macOS (이전 Mac OS X) 설치할 수 있습니다. MariaDB Server는 미리 컴파일된 Homebrew "bottle" 패키지로 이용 가능하며, 소스 빌드가 필요 없어 시간을 절약해

mariadb.com

https://wonpaper.tistory.com/399

 

[MySQL] Mac 에서 mariaDB 설치하기

맥에서 mariaDB 를 설치해본다. 맥전용 설치 파일이 없어서, 약간 귀찮은 과정을 거쳐야한다. Homebrew 으로 mariaDB 를 실제 설치하는 방식이다. 1. X-Code 설치 - Homebrew 를 설치가능하도록 해준다. : 터미

wonpaper.tistory.com

https://light-tree.tistory.com/247

 

macOS에서 MariaDB db생성, 계정생성, 권한부여

mariadb를 실행합니다. root@MacBookAir var % mariadb Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.7.3-MariaDB Homebrew Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others

light-tree.tistory.com

https://reddb.tistory.com/108

 

[MariaDB] 마리아DB SQL 쿼리 기본 - SELECT (MySQL)

[MariaDB] 마리아DB SQL 쿼리 기본 - SELECT (MySQL) DB목록 조회 SHOW DATABASES; DB선택 USE DB명; 선택된 DB에 존재하는 테이블 정보 조회 SHOW TABLE STATUS; -- 테이블 이름만 간단히 볼 때는 SHOW TABLES; 테이블 조회(S

reddb.tistory.com

 

728x90
반응형