• Stars
    star
    876
  • Rank 52,107 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created over 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. Documentation & Download: http://dev.mysql.com/doc/connector-python/en

MySQL Connector/Python

MySQL Connector/Python enables Python programs to access MySQL databases, using an API that is compliant with the Python Database API Specification v2.0 (PEP 249). It also contains an implementation of the X DevAPI, an Application Programming Interface for working with the MySQL Document Store.

Installation

The recommended way to install Connector/Python is via pip.

Make sure you have a recent pip version installed on your system. If your system already has pip installed, you might need to update it. Or you can use the standalone pip installer.

shell> pip install mysql-connector-python

Please refer to the installation tutorial for installation alternatives.

Getting Started

Using the MySQL classic protocol:

import mysql.connector

# Connect to server
cnx = mysql.connector.connect(
    host="127.0.0.1",
    port=3306,
    user="mike",
    password="s3cre3t!")

# Get a cursor
cur = cnx.cursor()

# Execute a query
cur.execute("SELECT CURDATE()")

# Fetch one result
row = cur.fetchone()
print("Current date is: {0}".format(row[0]))

# Close connection
cnx.close()

Using the MySQL X DevAPI:

import mysqlx

# Connect to server
session = mysqlx.get_session(
   host="127.0.0.1",
   port=33060,
   user="mike",
   password="s3cr3t!")
schema = session.get_schema("test")

# Use the collection "my_collection"
collection = schema.get_collection("my_collection")

# Specify which document to find with Collection.find()
result = collection.find("name like :param") \
                   .bind("param", "S%") \
                   .limit(1) \
                   .execute()

# Print document
docs = result.fetch_all()
print(r"Name: {0}".format(docs[0]["name"]))

# Close session
session.close()

Please refer to the MySQL Connector/Python Developer Guide and the MySQL Connector/Python X DevAPI Reference for a complete usage guide.

Additional Resources

Contributing

There are a few ways to contribute to the Connector/Python code. Please refer to the contributing guidelines for additional information.

License

Please refer to the README.txt and LICENSE.txt files, available in this repository, for further details.

More Repositories

1

mysql-server

MySQL Server, the world's most popular open source database, and MySQL Cluster, a real-time, open source transactional database.
C++
10,830
star
2

mysql-connector-j

MySQL Connector/J
Java
908
star
3

mysql-workbench

MySQL Workbench is a unified visual tool for database architects, developers, and DBAs. MySQL Workbench provides data modeling, SQL development, and comprehensive administration tools for server configuration, user administration, backup, and much more.
C++
898
star
4

mysql-sys

The MySQL sys schema
PLpgSQL
828
star
5

mysql-operator

MySQL Operator for Kubernetes
Python
767
star
6

mysql-connector-cpp

MySQL Connector/C++ is a MySQL database connector for C++. It lets you develop C++ and C applications that connect to MySQL Server.
C++
634
star
7

mysql-proxy

MySQL Proxy is a simple program that sits between your client and MySQL server(s) and that can monitor, analyze or transform their communication. Its flexibility allows for a wide variety of uses, including load balancing, failover, query analysis, query filtering and modification, and many more.
C
420
star
8

mysql-connector-net

Connector/NET is a fully-managed ADO.NET driver for MySQL.
C#
291
star
9

mysql-utilities

MySQL Utilities is a set of easy-to-use scripts intended to make working with MySQL servers easier.
Python
267
star
10

mysql-shell

MySQL Shell is a new command line scriptable shell for MySQL. It supports JavaScript and Python.
C++
193
star
11

mysql-js

NoSQL node.js connector for MySQL Cluster
JavaScript
170
star
12

mysql-connector-nodejs

MySQL Connector Node.JS is a MySQL Connector using the X Protocol, which was introduced with MySQL 5.7.12.
JavaScript
154
star
13

mysql-router

MySQL Router is lightweight middleware that provides transparent routing between your application and any backend MySQL Servers.
C++
150
star
14

mysql-connector-odbc

This is the source for MySQL Connector/ODBC (myodbc), an ODBC (3.51) driver for connecting an ODBC-aware application to the MySQL Server.
C++
92
star
15

mysql-shell-plugins

Plugins for the MySQL Shell
TypeScript
73
star
16

mysql-for-excel

MySQL for Excel is an Excel Add-In that is installed and accessed from within the MS Excel Data tab offering a wizard-like interface arranged in an elegant,yet simple way to help users browse MySQL Schemas, Tables, Views, and Procedures and perform data operations against them using MS Excel as the vehicle to drive the data in and out MySQL Databases.
C#
65
star
17

mysql-for-vs

MySQL for Visual Studio provides access to MySQL objects and data without forcing your developers to leave Visual Studio. Designed and developed as a Visual Studio package, MySQL for Visual Studio integrates directly into Server Explorer providing a seamless experience for setting up new connections and working with database objects.
C#
36
star
18

mysql-ndb-operator

Kubernetes Operator for MySQL NDB Cluster.
Go
35
star
19

mysql-notifier

MySQL Notifier is a small utility that can keep watch over your Windows and MySQL services, notifying you of changes in their operation. Notifier is intended to run when Windows starts up and sits in the tray notification area watching the MySQL and Windows services you have configured.
C#
19
star
20

mysql-snap

Source files for building Ubuntu Snap images
Shell
13
star
21

mysql-configurator

MySQL Configurator
C#
5
star