Notice
Recent Posts
Recent Comments
Link
기록하는 개발자
[node.js 심화] shop _ jwt, mySQL 본문
728x90
https://github.com/kiwihannah/07_shop
1. 기본 코드
const jwt = require("jsonwebtoken");
const token = jwt.sign({ test: true }, "hannah"); //key 값은 복잡한 것을 사용 권장
console.log(token);
const decoded = jwt.verify(token, "hannah"); // 복호화할 때, key값은 필요 없지만 key 값이 유효화를 판단
console.log(decoded);
2. vscode에서 auth 오류가 날때, mysql 서버에서 아래 문장을 실행
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234'
2_1 모듈 삽입
npm i express
npm i jsonwebtoken -S
npm i joi -S
npm i sequelize mysql2 -S
npm i sequelize-cli -D
npx sequelize init
3. db 생성 코드
//User
npx sequelize model:generate --name User --attributes email:string,nickname:string,password:string
//Cart
npx sequelize model:generate --name Cart --attributes userId:integer,goodsId:integer,quantity:integer
//Goods
npx sequelize model:generate --name Goods --attributes name:string,tumbnailUrl:string,category:string,price:decimal
4. 우분투 mysql 세팅
$ sudo apt install -y mysql-server
$ sudo mysql_secure_installation
$ sudo /etc/init.d/mysql restart
$ sudo mysql -u root -p
mysql> CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'abcd1234';
mysql> create database study;
mysql> grant all privileges on study.* to 'dbuser'@'localhost';
mysql> flush privileges;
그 다음 /etc/mysql/mysql.conf.d/mysqld.cnf 파일의 [mysqld] 영역에서 bind-address 부분을 아래와 같이 주석 처리 합니다.
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#
# bind-address = 127.0.0.1
aws ec2 mysql을 윈도우의 mysql workbench로 접속해보겠습니다!
1. ec2 접속 후 cd/etc/mysql/mysql.conf.d 로 이동합니다.
2. sudo vi mysqld.cnf
3. bind-address 127.0.0.1 가 적힌줄 맨앞에 # 를 넣어 주석처리 해주기
4. mysql 접속(sudo /usr/bin/mysql -u root -p)
5. 외부접속 허용 sql문 입력
mysql> create user 'root'@'%' identified by '[password]';
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
'root' 대신 유저 이름을 넣어주시면되고, %는 모든 곳에서 접속 허용이라는 뜻입니다.
6. mysql 재시작하기
sudo service mysql restart
sudo ufw allow out 3306/tcp
sudo ufw allow in 3306/tcp
sudo service mysql restart
ufw allow는 포트를 열어줍니다. 명령어 실행 후 Rules updated가 나오면 정상입니다.'학습 노트 > 항해 99 강의 정리' 카테고리의 다른 글
| 5주차_flask, aws, gabia 프로젝트 완성 및 배포 (0) | 2021.12.28 |
|---|---|
| 4주차_Flask framework API, POST & GET Ajax (0) | 2021.12.26 |
| 3주차_Python, 크롤링, mongoDB (0) | 2021.12.24 |
| 2주차_ jQuery, Ajax (0) | 2021.12.24 |
| 1주차_ html, css, javascript 기본 문법 및 실습 (0) | 2021.12.21 |
Comments