[SK쉴더스 Rookies 19기] 클라우드 기반 스마트 융합보안 과정
01. MySQL
MySQL Installer 8.0.36 다운로드!
https://dev.mysql.com/downloads/installer/
MySQL :: Download MySQL Installer
Note: MySQL 8.0 is the final series with MySQL Installer. As of MySQL 8.1, use a MySQL product's MSI or Zip archive for installation. MySQL Server 8.1 and higher also bundle MySQL Configurator, a tool that helps configure MySQL Server.
dev.mysql.com
실습을 위한 데이터베이스 생성
create schema sampledb default character set utf8;
use sampledb;
create table members (
member_id int(11) not null auto_increment comment '회원 아이디',
member_name varchar(100) not null comment '회원 이름',
member_age int(3) comment '회원 나이',
member_email varchar(100) comment '회원 이메일',
primary key(member_id)
);
테스트 데이터 추가
use sampledb;
insert into members (member_name, member_age, member_email)
values ('홍길동', 23, 'hong@test.com');
pymysql 라이브러리를 설치(파이썬 - mysql 연동 목적)
>>> pip install pymysql
데이터를 조회해보기!
import pymysql
# 데이터베이스 연결
try:
with pymysql.connect(host="localhost", port=3306, user="springboot", passwd="p@ssw0rd", db="sampledb") as conn:
# 조회 쿼리
query = "select member_id, member_name, member_age, member_email from members"
# 커서 생성 후 조회 쿼리를 실행
with conn.cursor() as curr:
curr.execute(query)
# 조회 결과 출력
for c in curr:
print(c)
except pymysql.MySQLError as e:
print(e)
02. Faker 라이브러리 활용
Faker 라이브러리 설치
from faker import Faker
faker = Faker('ko-KR') # 한국 설정
for i in range(10):
print(faker.name(), faker.address(), faker.email())
실행 결과
사용 가능한 fake 데이터들!
728x90
'Rookies > 인프라 활용을 위한 파이썬' 카테고리의 다른 글
[SK shieldus Rookies 19기] django 입문 (0) | 2024.03.08 |
---|---|
[SK shieldus Rookies 19기] CLI 기반 CRUD 프로그램 실습 (0) | 2024.03.08 |
[SK shieldus Rookies 19기] 파이썬 자료형 - 07 (0) | 2024.02.29 |
[SK shieldus Rookies 19기] 파이썬 자료형 - 06 (0) | 2024.02.29 |
[SK shieldus Rookies 19기] 파이썬 자료형 - 05 (0) | 2024.02.29 |