Python/Python 시작하기

python MySQL 연결 삽질 feat. pymysql

arvigoes 2020. 12. 11. 00:28

파이썬으로 mysql 연결을 위해 검색을 하다 문제(?) 의 pymysql 을 알게 되었습니다.
많이들 사용하고 있는듯 하여 아무 의심없이 사용.
처음에는 아무 문제 없이 로그인 테이블 insert 다 잘되길래 잘 되는 것 같아 좋구나 하고 사용했습니다.

그런데 컴퓨터를 재부팅 한 뒤에 connect 단에서 부터 실패를 하였습니다. 
원인은


"cryptography is required for sha256_password or caching_sha2_password"

패스워드 암호화와 관련있는 내용인듯 한데 pymysql은 아무 옵션도 제공이 되지 않더군요

이를 해결하기 위해 cryptography 를 설치 하기로 경정!!!

pip install cryptography

결과는 실패!!!

이유는 

visual studio c++ build tool 이 없다고 하여
https://visualstudio.microsoft.com/downloads/

 

Download Visual Studio 2019 for Windows & Mac

Download Visual Studio Community, Professional, and Enterprise. Try Visual Studio IDE, Code or Mac for free today.

visualstudio.microsoft.com

에서 접속하여 다운로드. 설치!!! 이때 필 수 옵션은 

Visual C++ 빌드 도구 필히 설치 해야 합니다.

암튼 Build Tool 설치

다시 pip install cryptography

결과는 또 실패!!!

오류를 보니 

openssl 소스가 없어서 에러가 난듯. 또다시 이를 바드러 openssl 이동

slproweb.com/products/Win32OpenSSL.html

 

Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

Minimum system requirements: Windows XP or later 32MB RAM 200MHz CPU 30MB hard drive space Recommended system requirements: Windows XP or later 128MB RAM 500MHz CPU 50MB hard drive space April 21, 2020 - All users and applications should be using the OpenS

slproweb.com

여기에서 난 윈도우 64비트니까 64버젼으로 Win64_OpenSSL v1.1.1i 을 다운받아서 설치

또 또 다시 pip install cryptography

결과는 또 또 실패!!!

정확한 원인은 모르겠으나 누구는 32bit 버젼으로 설치하여 해결 하였다고 해서 32bit 버젼으로 다운로드!!

윈도우에서 설치를 거부!@@@@@@

 

 

orz... 여기서 다시 검색.

stackoverflow.com/questions/54477829/cryptography-is-required-for-sha256-password-or-caching-sha2-password

 

"cryptography is required for sha256_password or caching_sha2_password"

Good day. Hope your all are well. Can someone help me with fix this? I'm new to the MySQL environment. I'm trying to connect to MySQL Database remotely. I used the following python code and got t...

stackoverflow.com

mysql.connector 를 설치 하기로 함....

여기도 설치가 처음엔 안되었는데 

www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient.Then

 

Python Extension Packages for Windows - Christoph Gohlke

by Christoph Gohlke, Laboratory for Fluorescence Dynamics, University of California, Irvine. Updated on 15 December 2020 at 07:18 UTC. This page provides 32- and 64-bit Windows binaries of many scientific open-source extension packages for the official CPy

www.lfd.uci.edu

이 파일을 다운 받아서 mysqlclient-1.4.6-cp37-cp37m-win32.whl
수동으로 설치 후 ( pip install 다운경로/mysqlclient-1.4.6-cp37-cp37m-win32.whl )
pip install mysql-connector 를 설치 하여 

self.conn = mysql.connector.connect(host='localhost', user='root', password='pass', database = 'database', charset='utf8', auth_plugin='mysql_native_password')
cursor = self.conn.cursor()

을 통해 접속성공

요게 필요한 거 같음.

혹시 누가 pymysql 이 상황해결 하신다면 알려주시면 감사하겠습니다.
아마도 mysql-connector 를 쓸 것 같지만...

다른 분들은 저처럼 삽질 하지 마시고 mysql-connector 바로 쓰시라고 길게 남겨 봅니다.