:::: 개발 ::::/::: Oracle :::

Mysql 게시판 데이타베이스 / 테이블 생성 기록

nayha 2014. 4. 2. 17:14

database create / table create ...


/* 참고 URL http://javaclass1.tistory.com/122 */

use mysql;

show tables;

/*사용자 확인*/

select * from user;

/* 사용자 추가

create user '사용자이름'@'접속위치' identified by '비밀번호'; 

쿼리에서 접속 위치를 %로 하시면 어디에서든 그 계정으로는 접속이 가능합니다

create user 'test_BBS'@'%' identified by 'xxxxxxxx'; 

*/

create user 'test_BBS'@'%' identified by 'xxxxxxxx'; 

/*db 추가*/

create database test_BBS;


use test_bbs;


/*사용자별 데이터베이스 권한 주기

-- select * from db;  -- 권한 확인 

grant all privileges on 데이터베이스명.* to '사용자이름'@'%' identified by '사용자비밀번호';


flush privileges;

// 안될때 참고 URL

http://gnujava.com:8000/board/article_view.jsp?article_no=911&board_no=16&table_cd=EPAR06&table_no=06

*/


grant all privileges on test_bbs.* to 'test_BBS'@'%' identified by 'xxxxxxxx';


flush privileges;


/* 접속해 보기 

바뀐 아디 / 비번으로 접속후 

*/


기본 게시판 테이블 추가 ..

-- 회원테이블 

create table member (

email varchar(60) PRIMARY KEY,

passwd varchar(20) NOT NULL,

name varchar(20) NOT NULL,

mobile varchar(20)

);

-- 게시판 종류

create table board (

boardcd varchar(20),

boardnm varchar(40) NOT NULL,

constraint PK_BOARD PRIMARY KEY(boardcd)

);

-- 게시글

create table article (

articleno int,

boardcd varchar(20),

title varchar(200) NOT NULL,

content text,

email varchar(60),

hit int,

regdate date,

constraint PK_ARTICLE PRIMARY KEY(articleno),

constraint FK_ARTICLE FOREIGN KEY(boardcd) REFERENCES board(boardcd)

);

-- 덧글

create table comments (

commentno int,

articleno int,

email varchar(60),

memo varchar(4000),

regdate date, 

constraint PK_COMMENTS PRIMARY KEY(commentno)

);

-- 첨부파일 

create table attachfile (

attachfileno int,

filename varchar(50) NOT NULL,

filetype varchar(30),

filesize int,

articleno int,

constraint PK_ATTACHFILE PRIMARY KEY(attachfileno)

);


insert into board values ('free','자유게시판');

insert into board values ('qna','QnA게시판');

insert into board values ('data','자료실');

commit;

/*게시글 자동증가 추가 */

ALTER TABLE `article` CHANGE `articleno` `articleno` INT(11) NOT NULL AUTO_INCREMENT;

/*덧글 번호 자동증가 추가 */

ALTER TABLE `comments` CHANGE `commentno` `commentno` INT(11) NOT NULL AUTO_INCREMENT;

/*첨부파일 자동증가 추가 */

ALTER TABLE `attachfile` CHANGE `attachfileno` `attachfileno` INT(11) NOT NULL AUTO_INCREMENT;



반응형