[Package] MySQL Connector Python

2019. 1. 4. 21:59개발자료/Python


반응형

## 설치

> !pip install mysql-connector-python

--------------------------------------------------

Collecting mysql-connector-python

  Downloading https://files.pythonhosted.org/packages/a8/ee/f289712198419fe706b8789e6efaa3e25871dc4d6cbffde0976e0fb7ea2e/mysql_connector_python-8.0.13-cp36-cp36m-macosx_10_13_x86_64.whl (3.5MB)

    100% |████████████████████████████████| 3.5MB 697kB/s ta 0:00:011

Collecting protobuf>=3.0.0 (from mysql-connector-python)

  Downloading https://files.pythonhosted.org/packages/c7/27/133f225035b9539f2dcfebcdf9a69ff0152f56e0120160ec5c972ea7deb9/protobuf-3.6.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.2MB)

    100% |████████████████████████████████| 1.2MB 1.2MB/s ta 0:00:01

Requirement already satisfied: setuptools in /anaconda3/lib/python3.6/site-packages (from protobuf>=3.0.0->mysql-connector-python) (40.6.2)

Requirement already satisfied: six>=1.9 in /anaconda3/lib/python3.6/site-packages (from protobuf>=3.0.0->mysql-connector-python) (1.11.0)

Installing collected packages: protobuf, mysql-connector-python

Successfully installed mysql-connector-python-8.0.13 protobuf-3.6.1


## Import

import mysql.connector

from mysql.connector import  errorcode


## 접속

try:

dbconn = mysql.connector.connect(user="id", password="password", host="localhost", database="databasename", port=3306)

except mysql.connector.Error as err:

if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with your user name or password ER_ACCESS_DENIED_ERROR")

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database Does not exists"),

else:

print(err)

else:

print("success connect")


## SELECT



## INSERT



## UPDATE/DELETE



## 주의사항

필드에 zerofill 사용하지 않아야 함.

필드에 zerofill 사용시 SELECT 구문후 행을 구해오는 로직에서 Segmentation fault 오류 발생함










반응형

'개발자료 > Python' 카테고리의 다른 글

BeautifulSoup 사용법  (0) 2019.01.10
[Package] KoNLPy  (0) 2019.01.05
setup.py  (0) 2019.01.05
[Package] SQLite3  (0) 2019.01.03
Dynamic Import(동적 임포토)  (0) 2018.12.31