"파이썬 MySQL 쿼리"의 두 판 사이의 차이

23번째 줄: 23번째 줄:
for row in rows:
for row in rows:
print(row)
print(row)
# 연결 닫기
conn.close()
</source>
</source>



2017년 7월 21일 (금) 22:31 판

1 개요

파이썬 MySQL 쿼리
  • MySQLdb 모듈을 통하여 MySQL 쿼리

2 예시

import MySQLdb

#MySQL 연결
conn = MySQLdb.connect(host="호스트", password="비밀번호", db="데이터베이스", charset="utf8")

#연결 상태에서 커서 생성
curs = conn.cursor()

# 쿼리 문 
sql = "select * from 테이블명"
curs.execute(sql)

# 데이터 패치
rows = curs.fetchall()

# 출력
for row in rows:
	print(row)

# 연결 닫기
conn.close()

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}