1. PyMySQL 패키지 설치

> pip install PyMySQL

 ref) https://pypi.org/project/PyMySQL/

> pip install pandas

** pandas lib : DataFrame 라이브러리

 ref) https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html

 

2. Source 

import pymysql

import pandas as pd

 

# db 정보 설정

test_db = pymysql.connect(

    user='root', 

    passwd='********', 

    host='localhost', 

    port=3306,

    db='hybris', 

    charset='utf8'

)

 

try:

    # 커서 설정

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

 

    sql = "SELECT * FROM bankaccount"

 

    cursor.execute(sql)

 

    # fetchall()    모든 데이터를 한 번에 가져올 때 사용

    # fetchone()    한 번 호출에 하나의 행만 가져올 때 사용

    # fetchmany(n)  n개만큼의 데이터를 가져올 때 사용

    result = cursor.fetchall()

 

    result = pd.DataFrame(result)

 

    print(result)

 

finally:

    cursor.close() 

    test_db.close()

'Python > DB' 카테고리의 다른 글

Python procedure 호출 (mysql)  (1) 2021.05.27

pom.xml 파일에서 아래와 같은 오류가 발생시..

마지막 업데이트 삭제 후 upadte.

 

failure to transfer org.apache.maven:maven-core:pom:2.0.6 from https://repo1.maven.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of central.mirror has elapsed or updates are for

windows 

> cd %userprofile%\.m2\repository

> for /r %i in (*.lastUpdated) do del %i

*  *  *  *  * 수행할 명령어

분(0~59)/시(0~23)/일(1~31)/월(1~12)/요일(0~6)(일요일:0~토요일:6)

 

예시)

* * * * * /test.sh
→ 매 1분마다 /test.sh를 수행 (하루에 1440회[2])
15,45 * * * * /test.sh
→ 매시 15분, 45분에 /test.sh를 수행 (하루에 48회[3])
*/10 * * * * /test.sh
→ 10분마다 /test.sh를 수행 (하루에 144회[4])
0 2 * * * /test.sh
→ 매일 02:00에 /test.sh 를 수행 (하루에 1회)
30 */6 * * * /test.sh
→ 매 6시간마다 수행(00:30, 06:30, 12:30, 18:30)
30 1-23/6 * * * /test.sh
→ 1시부터 매 6시간마다 수행(01:30, 07:30, 13:30, 19:30)
0 8 * * 1-5 /test.sh
→ 평일(월요일~금요일) 08:00
0 8 * * 0,6 /test.sh
→ 주말(일요일, 토요일) 08:00

 

'OS > 기타' 카테고리의 다른 글

TELNET으로 SMTP 이용하여 메일 보내기  (0) 2015.10.13

+ Recent posts