hjoon0510 / research-journal

기록일지 (문제, 이슈, 에러, 스크린샷, 작업내용, 해결방법 등을 기록하는 저장소입니다.)
Apache License 2.0
1 stars 0 forks source link

20201010 (python3: 한글데이타를 mysql에 저장 에러 - 디버깅) #114

Open hjoon0510 opened 3 years ago

hjoon0510 commented 3 years ago

이곳은 프로젝트의 작업 내용들을 기록 및 보관하는 곳입니다. 수행한 작업들을 체계적으로 기록하면 문제들을 효과적으로 해결이 가능하고, 반복되는 실수들을 최소화하는데 큰 도움을 제공합니다.

작업내용

python3으로 한글데이타를 mysql DB에 저장이 안되거나, 해결을 하더라도 한글 정보가 정상적으로 mysql db에 저장되지 않았다.

image


    timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    # print(timestamp)

    # https://stackoverflow.com/questions/6202726/writing-utf-8-string-to-mysql-with-python
    # Open database connection
    db = MySQLdb.connect(cfg.mysql['host'],cfg.mysql['user'],cfg.mysql['passwd'],cfg.mysql['db'],charset='utf8')

    # Prepare a cursor object using cursor() method
    cursor = db.cursor()

문제원인
=======
* https://stackoverflow.com/questions/6202726/writing-utf-8-string-to-mysql-with-python

해결방법
=======

https://stackoverflow.com/questions/6202726/writing-utf-8-string-to-mysql-with-python

Open database connection

db = MySQLdb.connect(cfg.mysql['host'],cfg.mysql['user'],cfg.mysql['passwd'],cfg.mysql['db'],charset='utf8')



이상.