티스토리 뷰

순서

(1) MySQL 설치

(2) Python 라이브러리 설치

(3) Python 코드 작성 및 연결 테스트


(1) MySQL 설치

아래 URL 접속 후 다운로드 및 설치(Server Only 옵션으로 설치)

https://dev.mysql.com/downloads/windows/installer/

 

MySQL :: Download MySQL Installer

Select Operating System: Select Operating System… Microsoft Windows Select OS Version: All Windows (x86, 32-bit) Windows (x86, 32-bit), MSI Installer 8.0.25 2.4M (mysql-installer-web-community-8.0.25.0.msi) MD5: 7f64b7ca2c526c359919d9db1bc8d669 | Signatu

dev.mysql.com

 

(2) Python 라이브러리 설치

아래 명령어 실행

C:/> pip install PyMySQL

 

(3) Python 코드 작성 및 연결 테스트

### MySQL 으로 DB 연결 후 데이터 출력~!!
import pymysql
conn = pymysql.connect(host='127.0.0.1', user='root', passwd='your password', db='mysql')

cur = conn.cursor()
cur.execute("USE scraping")
cur.execute("SELECT * FROM pages WHERE id=1")
print(cur.fetchone())
cur.close()
conn.close()

 

댓글