| mysql을 설치해서 nodejs와 같이 사용해 봅니다. | |
| 나의 폴더 > ASP.NET MVC | 2014-01-16 (Thu) 15:08 | http://blog.dreamwiz.com/papasmf1/14018698 | 
1.   MySQL의 경우 http://mysql.org에서 커뮤니티 버전을 받으면 된다. download탭에 
있는 Community버전을 받으면 된다. 약 240메가로 워크밴치가 포함되어 있다. 
![]() 
이중에 msi로 되어 
있는 버전을 받아서 설치하면 된다. root계정에 암호 “1234”를 입력하고 계정을 하나 추가하면 된다. 설치는 비교적 
간단한다.  
2.   워크벤치에서 
database메뉴에서 연결을 하고 아래의 명령들을 실행한다. 
 
create database 
Company; 
use Company 
create table products 
( 
        
id      int     not null auto_increment primary 
key, 
        name 
varchar(50) not null, 
        
modelnumber varchar(15) not null, 
        
series varchar(30) not null 
);  
describe products;  
insert into products (name, modelnumber, series) 
values  
('Eric Clapton', '0112223344', 'Artist'); 
 
insert into products (name, modelnumber, series) 
values  
('kim', '0112223344', 
'Artist'), 
('park', '0112223344', 
'Artist'), 
('lee', '0112223344', 
'Artist'); 
select * from products; 
![]() 
3.   일반 도스창에서 아래와 같이 명령어를 입력해서 mysql에 연결하기 위한 모듈들을 받는다. 
npm install mysql 
![]() 
4.   mySQL과 연결은 아래와 같이 해서 실행하면 된다. 
 
(mysql01.js로 저장해서 실행한다.)  
var mysql = 
require('mysql'); 
//데이터베이스와 
연결 
var client = 
mysql.createClient({ 
    user: 
'root', 
    
password: '1234' 
}); 
//데이터베이스 쿼리를 
사용 
client.query('USE 
Company'); 
client.query('Select * From products', function 
(error, result, fields) { 
    if (error) { 
        
console.log('쿼리 문장에 오류가 
있습니다'); 
    } else 
{ 
        
console.log(result); 
    
} 
}); 
 | 



댓글 없음:
댓글 쓰기
참고: 블로그의 회원만 댓글을 작성할 수 있습니다.