PyMySQL
v1.1.1
이 패키지에는 PEP 249를 기반으로 하는 순수 Python MySQL 및 MariaDB 클라이언트 라이브러리가 포함되어 있습니다.
패키지가 PyPI에 업로드되었습니다.
pip로 설치할 수 있습니다:
$ python3 -m pip install PyMySQL
인증을 위해 "sha256_password" 또는 "caching_sha2_password"를 사용하려면 추가 종속성을 설치해야 합니다.
$ python3 -m pip install PyMySQL[rsa]
MariaDB의 "ed25519" 인증 방법을 사용하려면 추가 종속성을 설치해야 합니다.
$ python3 -m pip install PyMySQL[ed25519]
문서는 온라인에서 볼 수 있습니다: https://pymysql.readthedocs.io/
지원을 받으려면 StackOverflow를 참조하세요.
다음 예에서는 간단한 테이블을 사용합니다.
CREATE TABLE ` users ` (
` id ` int ( 11 ) NOT NULL AUTO_INCREMENT,
` email ` varchar ( 255 ) COLLATE utf8_bin NOT NULL ,
` password ` varchar ( 255 ) COLLATE utf8_bin NOT NULL ,
PRIMARY KEY ( ` id ` )
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin
AUTO_INCREMENT = 1 ;
import pymysql . cursors
# Connect to the database
connection = pymysql . connect ( host = 'localhost' ,
user = 'user' ,
password = 'passwd' ,
database = 'db' ,
cursorclass = pymysql . cursors . DictCursor )
with connection :
with connection . cursor () as cursor :
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor . execute ( sql , ( '[email protected]' , 'very-secret' ))
# connection is not autocommit by default. So you must commit to save
# your changes.
connection . commit ()
with connection . cursor () as cursor :
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor . execute ( sql , ( '[email protected]' ,))
result = cursor . fetchone ()
print ( result )
이 예는 다음을 인쇄합니다:
{ 'password' : 'very-secret' , 'id' : 1 }
PyMySQL은 MIT 라이센스에 따라 출시됩니다. 자세한 내용은 라이센스를 참조하세요.