Last week we released MySQL Connector/Python v1.0.10. Release notes can be found in the MySQL Developver Zone.
A notable fix in Connector/Python v1.0.10 which might interest a few users is adding support for LOAD DATA LOCAL INFILE. It allows you to import CSV using a simple SQL statement.
Please use the MySQL Bugs website to report any problem.
Some useful links:
Enjoy!
SQLAchemy has support for MySQL Connector/Python for a while now. Here is a little HOWTO showing how install both, and setup a database engine.
There are multiple ways of installing both projects, but here is the simplest using pip, whatever platform you use:
shell> pip install SQLAlchemy
shell> pip install mysql-connector-python
Start your SQLAlchemy engines using a URL pointing to Connector/Python. Note the connect_args argument which passes extra connection arguments to Connector/Python. In the following example we set the MySQL session variable time_zone to UTC:
from sqlalchemy import create_engine
DB_URI = "mysql+mysqlconnector://{user}:{password}@{host}:{port}/{db}"
engine = create_engine(DB_URI.format(
user ='sakila',
password = 'yoursecret',
host = '127.0.0.1',
db = 'test'),
connect_args = {'time_zone': '+00:00'}
)
That’s it. Now just continue with SQLAlchemy as usual.
Today we released MySQL Connector/Python v1.0.9. Release notes can be found in the MySQL Developver Zone.
Connector/Python v1.0.9 contains some important fixes, especially for the Windows platform. It also comes with a new connection argument called force_ipv6, and can be used to force IPv6 when an address resolves to both IPv4 and v6. Also, RPM packages have been made available in addition to the TAR/ZIP and MSI packages.
Please use the MySQL Bugs website to report any problem.
Some useful links:
Enjoy!
While creating a spec file for an RPM, I needed to generate the list of files installed by the RPM. Solution is simple, use the UNIX command find. Right..
My first attempt was the following:
%install
# copy the files
( cd %{buildroot} ; find -type f -print "/%P\n" ) > INSTALLED_FILES
If you do the above, you’ll find that all entries in INSTALLED_FILES are wrong: file name have ‘ATCH’ at the end. Why is this? Because %p is a special macro in RPM spec files.
You can try to escape %P in an RPM spec file. If you manage that, let me know, I couldn’t.
Here is the solution I came up with after lots of hacking: it defines the pattern used in the find command as a macro.
%define findpat %( echo "/%""P" )
%install
# copy the files
( cd %{buildroot} ; find -type f -print "%{findpat}\n" ) > INSTALLED_FILES
I hope you never have to do this though.
Last week we made a maintenance release for MySQL Connector v1.0 available. The announcement can be read in the MySQL forums and the history log is available online.
Connector/Python v1.0.8 does not introduce anything new, it only comes with bug fixes. Some are quite important and it’s probably good to upgrade.
Please use the MySQL Bugs website to report any problem.
Some useful links:
Happy holidays! Hope you don’t get a bad cold like we did at home..
Today, during MySQL Connect 2012 keynote, the General Availability of MySQL Connector/Python 1.0 was announced! This is the first GA release of Oracle’s pure Python database driver for MySQL.
MySQL Connector/Python v1.0 works with MySQL 5.5 and 5.6, but older versions of the MySQL servers are known to work. For Python, version v2.6, v2.7 and v3.1 and greater are officially supported. Python v2.4/2.5 are know to work as well.
As always, we welcome your feedback and questions through our bug system or using the MySQL Python forum.
Some useful links:
Enjoy!
Love Python? Dig MySQL? Want to meet Oracle’s MySQL Python Experts?
Come and join us at the MySQL Connect 2012 conference in San Fransisco next week, 29/30 September. My colleague Chuck and I are both giving 3 sessions in which we discuss MySQL Utilities and Connector/Python.
Overview of our session:
See you there!
We released the second beta of MySQL Connector/Python v1.0. You can download v1.0.6 from the MySQL website and the change history can be found in the online manual.
Usually, beta releases do not have big changes, but we had to push some code which did not make the previous one and it really had to go into v1.0. The exceptions raised by Connector/Python are now mapped against the ‘SQLState’ found in the MySQL server errors. This makes it much easier to maintain and clearer which exception can be expected. It is, however, possible to override how errors are raised using the custom_error_exception() function of the errors module.
We are also preparing our connector to support Python v3.3 which has now a release candidate out. Maintaining compatibility between minor Python v2 releases is a chore; keeping up with Python v3.x changes ain’t easy either.
This beta comes with a MSI distribution for Python v2.7. This hopefully makes it easier for Windows users to install Connector/Python since no shell has to be opened.
Some useful links:
Enjoy!
It is possible with MySQL Connector/Python to define your own cursor classes. A very good use case is to return rows as dictionary instead of tuples. This post shows how to do this using MySQL Connector/Python v1.0 and is an update for an older blog entry.
In the example below we are subclassing the MySQLCursor class to create a new class called MySQLCursorDict. We change the _row_to_python() method to return a dictionary instead of a tuple. The keys of the dictionary will be (unicode) column names.
from pprint import pprint
import mysql.connector
class MySQLCursorDict(mysql.connector.cursor.MySQLCursor):
def _row_to_python(self, rowdata, desc=None):
row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc)
if row:
return dict(zip(self.column_names, row))
return None
cnx = mysql.connector.connect(user='root', database='test')
cur = cnx.cursor(cursor_class=MySQLCursorDict)
cur.execute("SELECT c1, c2 FROM t1")
rows = cur.fetchall()
pprint(rows)
cur.close()
cnx.close()
The output of the above script would be (formatted):
[
{u'c1': 1,
u'c2': 10},
{u'c1': 2,
u'c2': 20}
]
Depending on your needs, you can subclass from any class found in the mysql.connector.cursor module, but note that you will need to change some other methods to make it work.
Yesterday we announced the availability of MySQL Connector/Python v1.0.5 beta. Today I’ve made it available on PyPI so it can be easily installed. Note that I did remove the old development release and when you upgrade or try v1.0.5, you should check the ChangeLog.
shell> pip install mysql-connector-python
For those wondering why the name includes ‘python’: it’s just to align it with other MySQL connectors and to keep the name consistent with other distribution types.
We welcome and appreciate feedback and comments for this first beta release through the forum and the MySQL Bugs database.
Recent Comments