SlideShare a Scribd company logo
1

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Developing with
MySQL Connector/Python
Dr. Paulo Jesus
Software Developer

2

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Program Agenda
 Introduction of Connector/Python
 Download and Installation
 Coding
 About Performance
 Frameworks and Applications

3

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Introduction

4

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Introducing MySQL Connector/Python

 MySQL Database Driver
 Pure Python, no 3rd party dependencies

 Python v2 and v3
 For MySQL, by MySQL
 Documentation
– http://dev.mysql.com/doc/connector-python/en/index.html

5

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Pure Python

 Written entirely using Python
 No compiling against MySQL client libraries

 Only Standard Library used
 Developed for Python v2 and v3
 PEP-249 compliant

6

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Current Connector/Python Versions

 v1.0
– GA since September 2012

– v1.0.12 released August 2013

 v1.1
– Alpha since June 2013

– Some new features:
 Prepared Statements and Pooling
 Django backend included

7

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Python Support
Overview of supported Python version
2.4

2.5

2.6

2.7

3.0

3.1

3.2

3.3

v1.0

?

?













v1.1

















Connector/Python

8

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
MySQL Server Support

 MySQL v5.5 and higher
 Known to work on earlier versions
– No old password hashing support
– MySQL v4.0 and older will not work

9

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Download & Installation

10

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Dependencies
Python!
 For Windows
– Install Python from http://python.org

 Other systems
– should have Python (2.6 or greater)

11

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Download

 MySQL Website
– http://dev.mysql.com/downloads/connector/python

 Available as
– TAR/ZIP archive
– RPM and Debian package

– Windows Installer (MSI)

 Launchpad
– https://launchpad.net/myconnpy

12

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Download

 Example file names:
– mysql-connector-python-1.1.1.zip

– mysql-connector-python-1.1.1-py2.7.msi
– mysql-connector-python-1.1.1.el6.noarch.rpm

 Architecture independent

13

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Installation: Using TAR/ZIP
Running setup.py
 Most common way
 Works anywhere
– .. where Python is installed

 For both Python v2 & v3

14

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Installation: Universal
Using setup.py
shell> unzip mysql-connector-1.0.12.zip
shell> cd mysql-connector-1.0.12
shell> python setup.py install
# Or any other Python binary
shell> /opt/python/3.3/bin/python3 setup.py install

15

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Installation using RPM and Debian package

# On Oracle Linux
shell> rpm -i mysql-connector-python-1.1.1.el6.noarch.rpm
# On Ubuntu
shell> dpkg -i 
mysql-connector-python_1.0.12-1ubuntu12.04_all.deb

16

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Installation: using PyPI
Python Package Index
shell> easy_install mysql-connector-python

or
shell> pip install mysql-connector-python

17

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Install Inside Virtual Environment
Useful for testing and new development
# If not installed yet
shell> pip install virtualenv
shell> virtualenv ENV
shell> source ENV/bin/activate
shell> pip install mysql-connector-python

18

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Coding

19

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Classes and Objects
mysql.connector module
 import mysql.connector
 mysql.connector.connect()
– accepts numerous arguments
– returns a MySQLConnection

20

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Classes and Objects
MySQLConnection
 MySQLConnection
– connects with MySQL

– retrieve server information
– reconfigure and reconnect
– commit/rollback transactions

– create MySQLCursor objects

21

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Classes and Objects
MySQLCursor
 MySQLCursor
– fetch & manipulate data

– transactions
– different flavors (buffered, raw)

22

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Connecting with MySQL
Basic connection
import mysql.connector
cnx = mysql.connector.connect(user='root',
host='prod.example.com')
print(cnx.connection_id)
cnx.close()

23

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Connecting with MySQL
Use a dict to hold configuration & use IPv6
CONFIG = {
'user': 'root',
'host': '::1',
}
cnx = mysql.connector.connect(**CONFIG)
print(cnx.connection_id)
cnx.close()
24

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Reconnecting with MySQL
Reconfigure and reconnect
cnx = mysql.connector.connect(**CONFIG)

cnx.config(user='joe', password='mysecret')
cnx.reconnect()
cnx.close()

25

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Cursor methods
MySQLCursor class
 execute(query, data)
– data is list of values

 fetchone()
– returns row as tuple

 fetchmany(20)
– Get the next 20 rows (or less) as list of tuples

 fetchall()
– Get all, or remaining, as list of tuples

26

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Fetching Data
Fetch a row
cur = cnx.cursor()
cur.execute("SELECT NOW()")
result= cur.fetchone()[0]
print(result)
cur.close()
# Result
(datetime.datetime(2013, 9, 2, 10, 41, 58))
27

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Fetching Data
Going through results using iterator
query = (
"SELECT id, last_name FROM employees "
"WHERE id > %s AND first_name LIKE %s"
)
cur.execute(query, (500, 'J%'))
for row in cur:
print("{id} {name}".format(id=row[0], name=row[1]))
28

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Manipulating data
Inserting, updating and deleting
insert_stmt = (
"INSERT INTO employees (first_name, last_name) "
"VALUES (%s, %s)
)
cur = cnx.cursor()
cur.execute(insert_stmt, ('John', 'Doe'))
print("ID of new employee: {id}".format(id=cur.lastrowid))
cnx.commit()
29

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Change Many Records
MySQLCursor.executemany()
data = [
('John', 'Doe'),
('Jane', 'Doe'),
]
cur.executemany(insert_stmt, data)
cnx.commit()

30

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Execute Multiple Statements

 Separated by semicolon ;
 Could return one or more results

 Example:
– "SELECT NOW(); SELECT CURRENT_USER()"

 Needs multi argument set to True
– Raises error if not
– cur.execute(query, multi=True)

31

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Executing Multiple Statements
Example
cur = cnx.cursor()
queries = "SELECT NOW(); SELECT CURRENT_USER()"
for mcur in cur.execute(query, multi=True):
if mcur.with_rows:
print(mcur.fetchall())

32

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Retrying a Transaction (1/2)
Using reconnect()
tries = 10
while tries:
tries -= 1
try:
if not cnx.is_connected():
cnx.reconnect()
cur = cnx.cursor()
cur.execute(insert, ('Joe',))
33

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Retrying a Transaction (2/2)
Using reconnect()
cur.execute(insert, ('Joe',))
except mysql.connector.Error as err:
if not tries:
raise
else:
cnx.commit()
break

34

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Some Performance Tips

35

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Push Work to Server
General tips
 Use MySQL functions
– Date/Time calculation,

– String operations, etc..

 Sorting using ORDER BY in queries
 Select what you need
– Don't SELECT *

36

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Push Work to Server: Example
Date calculation done by MySQL server
query =
"SELECT DATEDIFF( end, start) FROM events WHERE id = %s"
cur.execute(query, (1234,))
event_length = cur.fetchone()[0]

37

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Raw Data

 Use a raw cursor
– cnx.cursor(raw=True)

 No MySQL to Python conversion
– data are all strings

 It is faster in most cases
– dumping to CSV or create XML
– handle conversion elsewhere

38

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Bulk Load Using CSV

 Use LOAD DATA LOCAL INFILE
 Server configuration has to allow it
– local_infile=1

 Client flag has to be set

39

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Using LOAD DATA LOCAL INFILE

CONFIG = {
'user': 'root', 'host': 'fk.example.com',
'client_flags': [mysql.connector.ClientFlag.LOCAL_FILES]
}
sql = "LOAD DATA LOCAL INFILE %s INTO TABLE employees"
cur.execute(sql, ('employees.csv',))

40

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Frameworks and
Applications

41

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
MySQL Projects
Depending on Connector/Python
 MySQL Utilities
– Command line utilities

– Managing, dumping data, failover, ..

 MySQL Fabric
– Data distribution

– High-availability for groups of MySQL servers
 Both pure Python & no 3rd party modules

42

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
SQLAlchemy

 SQL Toolkit and ORM (Object Relational Mapper)
 Pythonic database access

 Used by lots of other (web) frameworks
 Connector/Python dialect included
– Since SQLAlchemy 0.6

43

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
SQLAlchemy: Usage
Connect String
from sqlalchemy import create_engine
DB_URI =
"mysql+mysqlconnector://{user}:{pwd}@{host}:{port}/{db}"
engine = create_engine(DB_URI.format(
user='joe', pwd='mysecret', db='employees',
host='127.0.0.1', port=3306)
)
44

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Django

 Web framework
 ORM and database API

 No support for Connector/Python
 But Connector/Python 1.1.1 supports Django
– Support features as microsecond precision
– Works with Django 1.4 and 1.5
– Python 3 support

45

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Django: Configuration
Using Connector/Python backend
# settings.py
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
}
}

46

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Q&A

47

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Q&A
More Information
 Documentation & Examples
– http://dev.mysql.com/doc/connector-python/en/index.html

 Download
– http://dev.mysql.com/downloads/connector/python/#downloads

 Blog
– http://geert.vanderkelen.org

 Feedback & Forum
– http://forums.mysql.com/list.php?50
– http://bugs.mysql.com/

48

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
Graphic Section Divider

49

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
50

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

More Related Content

What's hot

Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Frederic Descamps
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden Gate
Muhammad Qasim
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
Frederic Descamps
 
the State of the Dolphin - October 2020
the State of the Dolphin - October 2020the State of the Dolphin - October 2020
the State of the Dolphin - October 2020
Frederic Descamps
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
Frederic Descamps
 
101 2.4b use debian package management v2
101 2.4b use debian package management v2101 2.4b use debian package management v2
101 2.4b use debian package management v2
Acácio Oliveira
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package management
Acácio Oliveira
 
2.4.1 use debian package management v2
2.4.1 use debian package management v22.4.1 use debian package management v2
2.4.1 use debian package management v2
Acácio Oliveira
 
Tools, not only for Oracle RAC
Tools, not only for Oracle RACTools, not only for Oracle RAC
Tools, not only for Oracle RAC
Markus Flechtner
 
Rac nonrac clone
Rac nonrac cloneRac nonrac clone
Rac nonrac clone
stevejones167
 
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
Frederic Descamps
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial
KlausePaulino
 
RAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and DatabaseRAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and Database
Nikhil Kumar
 
Rac 12c optimization
Rac 12c optimizationRac 12c optimization
Rac 12c optimization
Riyaj Shamsudeen
 
Setup oracle golden gate 11g replication
Setup oracle golden gate 11g replicationSetup oracle golden gate 11g replication
Setup oracle golden gate 11g replication
Kanwar Batra
 
361 Rac
361 Rac361 Rac
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDSMySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
Frederic Descamps
 
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorialMySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
Frederic Descamps
 
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, UnicodeOracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
Markus Flechtner
 

What's hot (20)

Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
Inexpensive Datamasking for MySQL with ProxySQL - data anonymization for deve...
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden Gate
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
 
MySQL Router REST API
MySQL Router REST APIMySQL Router REST API
MySQL Router REST API
 
the State of the Dolphin - October 2020
the State of the Dolphin - October 2020the State of the Dolphin - October 2020
the State of the Dolphin - October 2020
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
 
101 2.4b use debian package management v2
101 2.4b use debian package management v2101 2.4b use debian package management v2
101 2.4b use debian package management v2
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package management
 
2.4.1 use debian package management v2
2.4.1 use debian package management v22.4.1 use debian package management v2
2.4.1 use debian package management v2
 
Tools, not only for Oracle RAC
Tools, not only for Oracle RACTools, not only for Oracle RAC
Tools, not only for Oracle RAC
 
Rac nonrac clone
Rac nonrac cloneRac nonrac clone
Rac nonrac clone
 
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
MySQL Document Store - How to replace a NoSQL database by MySQL without effor...
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial
 
RAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and DatabaseRAC-Installing your First Cluster and Database
RAC-Installing your First Cluster and Database
 
Rac 12c optimization
Rac 12c optimizationRac 12c optimization
Rac 12c optimization
 
Setup oracle golden gate 11g replication
Setup oracle golden gate 11g replicationSetup oracle golden gate 11g replication
Setup oracle golden gate 11g replication
 
361 Rac
361 Rac361 Rac
361 Rac
 
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDSMySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
MySQL Database Service Webinar: Upgrading from on-premise MySQL to MDS
 
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorialMySQL InnoDB Cluster and Group Replication in a nutshell  hands-on tutorial
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
 
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, UnicodeOracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
Oracle Globalization Support, NLS_LENGTH_SEMANTICS, Unicode
 

Similar to Con4445 jesus

MySQL JSON Functions
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON Functions
Sveta Smirnova
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helper
Mark Leith
 
Enterprise manager 13c -let's connect to the Oracle Cloud
Enterprise manager 13c -let's connect to the Oracle CloudEnterprise manager 13c -let's connect to the Oracle Cloud
Enterprise manager 13c -let's connect to the Oracle Cloud
Trivadis
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/Python
Jesper Wisborg Krogh
 
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.
Miguel Araújo
 
Stackato Presentation Techzone 2013
Stackato Presentation Techzone 2013Stackato Presentation Techzone 2013
Stackato Presentation Techzone 2013
Martin Kenneth Michalsky
 
Pixels_Camp
Pixels_CampPixels_Camp
Pixels_Camp
Nelson Gomes
 
20161029 py con-mysq-lv3
20161029 py con-mysq-lv320161029 py con-mysq-lv3
20161029 py con-mysq-lv3
Ivan Ma
 
MySQL Administration and Monitoring
MySQL Administration and MonitoringMySQL Administration and Monitoring
MySQL Administration and Monitoring
Mark Leith
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Arun Gupta
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
Geir Høydalsvik
 
MySQL Quick Dive
MySQL Quick DiveMySQL Quick Dive
MySQL Quick Dive
Sudipta Kumar Sahoo
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
Mark Leith
 
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Sven Sandberg
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara
NetApp
 
Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
Women in Technology Poland
 
Oracle Solaris 11.1 New Features
Oracle Solaris 11.1 New FeaturesOracle Solaris 11.1 New Features
Oracle Solaris 11.1 New Features
Orgad Kimchi
 
Python and the MySQL Document Store
Python and the MySQL Document StorePython and the MySQL Document Store
Python and the MySQL Document Store
Jesper Wisborg Krogh
 
20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell
Ivan Ma
 

Similar to Con4445 jesus (20)

MySQL JSON Functions
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON Functions
 
Performance schema and_ps_helper
Performance schema and_ps_helperPerformance schema and_ps_helper
Performance schema and_ps_helper
 
Enterprise manager 13c -let's connect to the Oracle Cloud
Enterprise manager 13c -let's connect to the Oracle CloudEnterprise manager 13c -let's connect to the Oracle Cloud
Enterprise manager 13c -let's connect to the Oracle Cloud
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/Python
 
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.
 
Stackato Presentation Techzone 2013
Stackato Presentation Techzone 2013Stackato Presentation Techzone 2013
Stackato Presentation Techzone 2013
 
Pixels_Camp
Pixels_CampPixels_Camp
Pixels_Camp
 
20161029 py con-mysq-lv3
20161029 py con-mysq-lv320161029 py con-mysq-lv3
20161029 py con-mysq-lv3
 
MySQL Administration and Monitoring
MySQL Administration and MonitoringMySQL Administration and Monitoring
MySQL Administration and Monitoring
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
 
MySQL Quick Dive
MySQL Quick DiveMySQL Quick Dive
MySQL Quick Dive
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
 
CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara CloudStack Meetup Santa Clara
CloudStack Meetup Santa Clara
 
Marcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL WorkbenchMarcin Szałowicz - MySQL Workbench
Marcin Szałowicz - MySQL Workbench
 
Oracle Solaris 11.1 New Features
Oracle Solaris 11.1 New FeaturesOracle Solaris 11.1 New Features
Oracle Solaris 11.1 New Features
 
Python and the MySQL Document Store
Python and the MySQL Document StorePython and the MySQL Document Store
Python and the MySQL Document Store
 
20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell
 

Recently uploaded

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
Mydbops
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 

Recently uploaded (20)

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Must Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during MigrationMust Know Postgres Extension for DBA and Developer during Migration
Must Know Postgres Extension for DBA and Developer during Migration
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 

Con4445 jesus

  • 1. 1 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 2. Developing with MySQL Connector/Python Dr. Paulo Jesus Software Developer 2 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 3. Program Agenda  Introduction of Connector/Python  Download and Installation  Coding  About Performance  Frameworks and Applications 3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 4. Introduction 4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 5. Introducing MySQL Connector/Python  MySQL Database Driver  Pure Python, no 3rd party dependencies  Python v2 and v3  For MySQL, by MySQL  Documentation – http://dev.mysql.com/doc/connector-python/en/index.html 5 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 6. Pure Python  Written entirely using Python  No compiling against MySQL client libraries  Only Standard Library used  Developed for Python v2 and v3  PEP-249 compliant 6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 7. Current Connector/Python Versions  v1.0 – GA since September 2012 – v1.0.12 released August 2013  v1.1 – Alpha since June 2013 – Some new features:  Prepared Statements and Pooling  Django backend included 7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 8. Python Support Overview of supported Python version 2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3 v1.0 ? ?       v1.1         Connector/Python 8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 9. MySQL Server Support  MySQL v5.5 and higher  Known to work on earlier versions – No old password hashing support – MySQL v4.0 and older will not work 9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 10. Download & Installation 10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 11. Dependencies Python!  For Windows – Install Python from http://python.org  Other systems – should have Python (2.6 or greater) 11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 12. Download  MySQL Website – http://dev.mysql.com/downloads/connector/python  Available as – TAR/ZIP archive – RPM and Debian package – Windows Installer (MSI)  Launchpad – https://launchpad.net/myconnpy 12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 13. Download  Example file names: – mysql-connector-python-1.1.1.zip – mysql-connector-python-1.1.1-py2.7.msi – mysql-connector-python-1.1.1.el6.noarch.rpm  Architecture independent 13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 14. Installation: Using TAR/ZIP Running setup.py  Most common way  Works anywhere – .. where Python is installed  For both Python v2 & v3 14 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 15. Installation: Universal Using setup.py shell> unzip mysql-connector-1.0.12.zip shell> cd mysql-connector-1.0.12 shell> python setup.py install # Or any other Python binary shell> /opt/python/3.3/bin/python3 setup.py install 15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 16. Installation using RPM and Debian package # On Oracle Linux shell> rpm -i mysql-connector-python-1.1.1.el6.noarch.rpm # On Ubuntu shell> dpkg -i mysql-connector-python_1.0.12-1ubuntu12.04_all.deb 16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 17. Installation: using PyPI Python Package Index shell> easy_install mysql-connector-python or shell> pip install mysql-connector-python 17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 18. Install Inside Virtual Environment Useful for testing and new development # If not installed yet shell> pip install virtualenv shell> virtualenv ENV shell> source ENV/bin/activate shell> pip install mysql-connector-python 18 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 19. Coding 19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 20. Classes and Objects mysql.connector module  import mysql.connector  mysql.connector.connect() – accepts numerous arguments – returns a MySQLConnection 20 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 21. Classes and Objects MySQLConnection  MySQLConnection – connects with MySQL – retrieve server information – reconfigure and reconnect – commit/rollback transactions – create MySQLCursor objects 21 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 22. Classes and Objects MySQLCursor  MySQLCursor – fetch & manipulate data – transactions – different flavors (buffered, raw) 22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 23. Connecting with MySQL Basic connection import mysql.connector cnx = mysql.connector.connect(user='root', host='prod.example.com') print(cnx.connection_id) cnx.close() 23 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 24. Connecting with MySQL Use a dict to hold configuration & use IPv6 CONFIG = { 'user': 'root', 'host': '::1', } cnx = mysql.connector.connect(**CONFIG) print(cnx.connection_id) cnx.close() 24 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 25. Reconnecting with MySQL Reconfigure and reconnect cnx = mysql.connector.connect(**CONFIG) cnx.config(user='joe', password='mysecret') cnx.reconnect() cnx.close() 25 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 26. Cursor methods MySQLCursor class  execute(query, data) – data is list of values  fetchone() – returns row as tuple  fetchmany(20) – Get the next 20 rows (or less) as list of tuples  fetchall() – Get all, or remaining, as list of tuples 26 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 27. Fetching Data Fetch a row cur = cnx.cursor() cur.execute("SELECT NOW()") result= cur.fetchone()[0] print(result) cur.close() # Result (datetime.datetime(2013, 9, 2, 10, 41, 58)) 27 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 28. Fetching Data Going through results using iterator query = ( "SELECT id, last_name FROM employees " "WHERE id > %s AND first_name LIKE %s" ) cur.execute(query, (500, 'J%')) for row in cur: print("{id} {name}".format(id=row[0], name=row[1])) 28 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 29. Manipulating data Inserting, updating and deleting insert_stmt = ( "INSERT INTO employees (first_name, last_name) " "VALUES (%s, %s) ) cur = cnx.cursor() cur.execute(insert_stmt, ('John', 'Doe')) print("ID of new employee: {id}".format(id=cur.lastrowid)) cnx.commit() 29 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 30. Change Many Records MySQLCursor.executemany() data = [ ('John', 'Doe'), ('Jane', 'Doe'), ] cur.executemany(insert_stmt, data) cnx.commit() 30 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 31. Execute Multiple Statements  Separated by semicolon ;  Could return one or more results  Example: – "SELECT NOW(); SELECT CURRENT_USER()"  Needs multi argument set to True – Raises error if not – cur.execute(query, multi=True) 31 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 32. Executing Multiple Statements Example cur = cnx.cursor() queries = "SELECT NOW(); SELECT CURRENT_USER()" for mcur in cur.execute(query, multi=True): if mcur.with_rows: print(mcur.fetchall()) 32 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 33. Retrying a Transaction (1/2) Using reconnect() tries = 10 while tries: tries -= 1 try: if not cnx.is_connected(): cnx.reconnect() cur = cnx.cursor() cur.execute(insert, ('Joe',)) 33 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 34. Retrying a Transaction (2/2) Using reconnect() cur.execute(insert, ('Joe',)) except mysql.connector.Error as err: if not tries: raise else: cnx.commit() break 34 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 35. Some Performance Tips 35 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 36. Push Work to Server General tips  Use MySQL functions – Date/Time calculation, – String operations, etc..  Sorting using ORDER BY in queries  Select what you need – Don't SELECT * 36 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 37. Push Work to Server: Example Date calculation done by MySQL server query = "SELECT DATEDIFF( end, start) FROM events WHERE id = %s" cur.execute(query, (1234,)) event_length = cur.fetchone()[0] 37 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 38. Raw Data  Use a raw cursor – cnx.cursor(raw=True)  No MySQL to Python conversion – data are all strings  It is faster in most cases – dumping to CSV or create XML – handle conversion elsewhere 38 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 39. Bulk Load Using CSV  Use LOAD DATA LOCAL INFILE  Server configuration has to allow it – local_infile=1  Client flag has to be set 39 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 40. Using LOAD DATA LOCAL INFILE CONFIG = { 'user': 'root', 'host': 'fk.example.com', 'client_flags': [mysql.connector.ClientFlag.LOCAL_FILES] } sql = "LOAD DATA LOCAL INFILE %s INTO TABLE employees" cur.execute(sql, ('employees.csv',)) 40 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 41. Frameworks and Applications 41 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 42. MySQL Projects Depending on Connector/Python  MySQL Utilities – Command line utilities – Managing, dumping data, failover, ..  MySQL Fabric – Data distribution – High-availability for groups of MySQL servers  Both pure Python & no 3rd party modules 42 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 43. SQLAlchemy  SQL Toolkit and ORM (Object Relational Mapper)  Pythonic database access  Used by lots of other (web) frameworks  Connector/Python dialect included – Since SQLAlchemy 0.6 43 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 44. SQLAlchemy: Usage Connect String from sqlalchemy import create_engine DB_URI = "mysql+mysqlconnector://{user}:{pwd}@{host}:{port}/{db}" engine = create_engine(DB_URI.format( user='joe', pwd='mysecret', db='employees', host='127.0.0.1', port=3306) ) 44 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 45. Django  Web framework  ORM and database API  No support for Connector/Python  But Connector/Python 1.1.1 supports Django – Support features as microsecond precision – Works with Django 1.4 and 1.5 – Python 3 support 45 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 46. Django: Configuration Using Connector/Python backend # settings.py DATABASES = { 'default': { 'ENGINE': 'mysql.connector.django', } } 46 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 47. Q&A 47 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 48. Q&A More Information  Documentation & Examples – http://dev.mysql.com/doc/connector-python/en/index.html  Download – http://dev.mysql.com/downloads/connector/python/#downloads  Blog – http://geert.vanderkelen.org  Feedback & Forum – http://forums.mysql.com/list.php?50 – http://bugs.mysql.com/ 48 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 49. Graphic Section Divider 49 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.
  • 50. 50 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.