Skip to content

T2BE/mysql-connector

 
 

Repository files navigation

MySQL Connector/Python

This is a fork of MySQL offical maintained mysql-connector-python. Aim to get started easily for beginners.

Installation

From PyPI (recommend)

pip install mysql-connector

From source code

python setup.py install

Documentation

Documentation for all Connector/Python versions can be found online here:

dev.mysql.com/doc/connector-python/en/

Examples

import mysql.connector from mysql.connector import errorcode config = { 'user': 'root', 'password': '', 'host': '127.0.0.1', 'database': 'test' } cnx = cur = None try: cnx = mysql.connector.connect(**config) except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print('Something is wrong with your user name or password') elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) else: cur = cnx.cursor() cur.execute('show databases;') for row in cur.fetchall(): print(row) finally: if cur: cur.close() if cnx: cnx.close()

About

MySQL driver written in Python which implements the DB API v2.0 specification (PEP-249).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 91.1%
  • C 8.4%
  • Other 0.5%