Web Dev
Node.js - MySQL 연동 /MySQL로 홈페이지 구현
이준호
2023. 2. 23. 12:25
반응형
--
-- Table structure for table `author`
--
CREATE TABLE `author` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`profile` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
);
--
-- Dumping data for table `author`
--
INSERT INTO `author` VALUES (1,'egoing','developer');
INSERT INTO `author` VALUES (2,'duru','database administrator');
INSERT INTO `author` VALUES (3,'taeho','data scientist, developer');
--
-- Table structure for table `topic`
--
CREATE TABLE `topic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(30) NOT NULL,
`description` text,
`created` datetime NOT NULL,
`author_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
--
-- Dumping data for table `topic`
--
INSERT INTO `topic` VALUES (1,'MySQL','MySQL is...','2018-01-01 12:10:11',1);
INSERT INTO `topic` VALUES (2,'Oracle','Oracle is ...','2018-01-03 13:01:10',1);
INSERT INTO `topic` VALUES (3,'SQL Server','SQL Server is ...','2018-01-20 11:01:10',2);
INSERT INTO `topic` VALUES (4,'PostgreSQL','PostgreSQL is ...','2018-01-23 01:03:03',3);
INSERT INTO `topic` VALUES (5,'MongoDB','MongoDB is ...','2018-01-30 12:31:03',1);
mysql 새로운 스키마 생성하여 테이블 생성 및 값 넣어주기 !!
확인 가능 !
npm install 명령어를 통해 필요한 node modules 설치
-> mysql을 컨트롤 할 수 있는 node.js 의 모듈을 찾아 보자 !
npm install --save mysql
해당 명령어로 진행하면
반응형
mysql -> dependencies에 기록된걸 확인할 수 있다.
[
RowDataPacket {
id: 1,
title: 'MySQL',
description: 'MySQL is...',
created: 2018-01-01T03:10:11.000Z,
author_id: 1
},
RowDataPacket {
id: 2,
title: 'Oracle',
description: 'Oracle is ...',
created: 2018-01-03T04:01:10.000Z,
author_id: 2
},
RowDataPacket {
id: 4,
title: 'PostgreSQL',
description: 'PostgreSQL is ...',
created: 2018-01-22T16:03:03.000Z,
author_id: 3
},
RowDataPacket {
id: 5,
title: 'MongoDB',
description: 'MongoDB is ...',
created: 2018-01-30T03:31:03.000Z,
author_id: 1
}
]
object 로 띄는 이유는 topic[i] 자체는 그냥 객체를 그 자체를 의미
이와 같이 바꿔 주면 된다.
https://www.npmjs.com/package/mysql
mysql
A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.. Latest version: 2.18.1, last published: 2 years ago. Start using mysql in your project by running `npm i mysql`. There are 6643 other projects i
www.npmjs.com
반응형