Skip to content

Instantly share code, notes, and snippets.

@bongbongco
Last active October 14, 2016 17:00
Show Gist options
  • Save bongbongco/a9560933b2af5949ab2097955b6a31e7 to your computer and use it in GitHub Desktop.
Save bongbongco/a9560933b2af5949ab2097955b6a31e7 to your computer and use it in GitHub Desktop.
import pymysql
# MySQL Connection 연결
conn = pymysql.connect(host='localhost', user='tester', password='',
db='testdb', charset='utf8')
# Connection 으로부터 Cursor 생성
curs = conn.cursor()
# SQL문 실행
sql = "select * from customer"
curs.execute(sql)
# 데이타 Fetch
rows = curs.fetchall()
print(rows) # 전체 rows
# print(rows[0]) # 첫번째 row: (1, '김정수', 1, '서울')
# print(rows[1]) # 두번째 row: (2, '강수정', 2, '서울')
# Connection 닫기
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment