mysql 설치, 파이썬 연동

허선우·2021년 6월 8일
0

PYTHON

목록 보기
14/17
post-thumbnail

mysql 설치 블로그

m.blog.naver.com/bjh7007/221829548634


🎈Oracle, my SQL비교


my sql을 실행하고 가장 먼저 자동commit이 활성화 되어있는지 확인합니다.
자동 커밋을 활성화하면 commit을 입력하지 않아도 자동으로 커밋이 됩니다. (roll back사용이 안됨) 그럼 중요한 데이터가 손상될 수 있으니 자동커밋을 해제 합니다.


sql과 파이썬 연동

1. 아나콘다 프롬프트에서 pymysql을 설치한다.

conda install pymysql입력

2. 2. 주피터 노트북에서 아래와 같이 코딩하라.

import pandas as pd
import pymysql

conn = pymysql.connect(host ='localhost',user ='root', password = 'tiger',db ='orcl',charset = 'utf8')    #본인의 user name, password를 입력해준다. 
cursors = conn.cursor()
sql = "select * from emp"
cursors.execute(sql)
row = cursors.fetchall()

colname = cursors.description
col = []
for i in colname:
    col.append(i[0].lower())
emp = pd.DataFrame(row, columns = col)

이제 주피터, my_SQL모두 사용할 수있다.
단 my_SQL에서 수정을 하였으면 주피터에서 clear을 한번 하고 재시작한다.

0개의 댓글