GithubHelp home page GithubHelp logo

heatdeath / mysql-connector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sanpingz/mysql-connector

0.0 2.0 0.0 12.12 MB

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

Home Page: http://dev.mysql.com/doc/connector-python/en/

License: Other

Python 88.43% C 6.30% C++ 2.04% Protocol Buffer 3.04% Shell 0.19%

mysql-connector's Introduction

MySQL Connector/Python

Requirements

mysql-connector (version >= 2.2.3) requires Protobuf C++ (version >= 2.6.0)

Install Protobuf on your platform. e.g., on macOS: brew install protobuf, and then specify the install paths:

# Use the proper paths based on your installation
export MYSQLXPB_PROTOBUF_INCLUDE_DIR=/usr/local/opt/protobuf/include
export MYSQLXPB_PROTOBUF_LIB_DIR=/usr/local/opt/protobuf/lib
export MYSQLXPB_PROTOC=/usr/local/opt/protobuf/bin/protoc

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/

The source distribution of Connector/Python also contains example scripts. They can be found in the examples/ directory.

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()

mysql-connector's People

Contributors

amitab avatar bkandasa avatar isrgomez avatar kboortz avatar nmariz avatar peeyushgupta avatar sanpingz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.