728x90
반응형
1. 마리아 db 사용자 생성 및 권한 부여
1. 마리아 db 접속
ubuntu@instance-mariadb:~$ mariadb -u root -p
2. 사용자 생성
create user 'blogdb'@'%' identified by 'passwordtest';
MariaDB [mysql]> create user 'blogdb'@'%' identified by 'passwordtest';
Query OK, 0 rows affected (0.003 sec)
3. db접속 권한 부여
grant all privileges on blogdb.* to 'blogdb'@'%';
MariaDB [mysql]> grant all privileges on blogdb.* to 'blogdb'@'%';
Query OK, 0 rows affected (0.005 sec)
4. 권한적용
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.002 sec)
5. 권한확인
show grants for 'blogdb'@'%';
MariaDB [mysql]> show grants for 'blogdb'@'%';
+-------------------------------------------------------------------------------------------------------+
| Grants for blogdb@% |
+-------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `blogdb`@`%` IDENTIFIED BY PASSWORD '*B2F3668640C8558029C7313B387D139DD6491FC5' |
| GRANT ALL PRIVILEGES ON `blogdb`.* TO `blogdb`@`%` |
+-------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
6. 계정, 권한 삭제
drop user 'blogdb'@'%';
revoke all on blogdb.* from 'blogdb'@'%';
2. php 마리아 db 연결 설정
<html>
<body>
<h1>
test!!
</h1>
</body>
</html>
<?php
echo "Maria DB 연결 테스트<br>";
$hostname="127.0.0.1";
$dbuserid="blogdb";
$dbpasswd="passwordtest";
$dbname="blogdb";
$dbport=3306;
$db = new mysqli($hostname,$dbuserid,$dbpasswd,$dbname,$dbport);
if($db){
echo "connect: success<br>";
}else{
echo "connect: failure<br>";
}
$result = mysqli_query($db,'SELECT VERSION() as VERSION');
$data = mysqli_fetch_assoc($result);
echo $data['VERSION'];
?>
3. 게시판 테스트 테이블 만들기
CREATE TABLE `board` (
`bid` int(11) NOT NULL AUTO_INCREMENT COMMENT '게시판의 primary key',
`userid` varchar(45) DEFAULT NULL COMMENT '사용자아이디',
`subject` varchar(300) DEFAULT NULL COMMENT '제목',
`content` text DEFAULT NULL COMMENT '게시판 내용',
`regdate` datetime DEFAULT current_timestamp() COMMENT '등록일자',
`modifydate` datetime DEFAULT NULL COMMENT '수정일자',
`status` tinyint(1) DEFAULT 1 COMMENT '게시물상태코드',
PRIMARY KEY (`bid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='게시판';
728x90
반응형
댓글