pymysql, python mysql

Jinno·2022년 8월 2일
0

python

목록 보기
10/21
import pymysql
import pandas as pd

test_db = pymysql.connect(
    user='root',
    passwd='1111222',
    host='localhost',
    db='testdb',
    charset='utf8'
)

cursor = test_db.cursor(pymysql.cursors.DictCursor)

Select

sql = "select * from facility limit 10"
cursor.execute(sql)
result = cursor.fetchall()
result = pd.DataFrame(result)

orderby

sql = 'select * from facility order by ciname'
cursor.execute(sql)
result = cursor.fetchall()
result = pd.DataFrame(result)

where

sql = 'select * from facility where name3 = "호랑이"'
cursor.execute(sql)
result = cursor.fetchall()
result = pd.DataFrame(result)

where-2

sql = 'select * from facility where name3 = %s'
cursor.execute(sql, ('호랑이'))
result = cursor.fetchall()
result = pd.DataFrame(result)
profile
Innovation, 기록용

0개의 댓글