通过SQLAlchemy的Python 3和mysql [英] Python 3 and mysql through SQLAlchemy

查看:94
本文介绍了通过SQLAlchemy的Python 3和mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前:

  • 已安装并运行SQLAlchemy(或至少导入了v0.8.0b2)
  • Mysql(v5.5.16)
  • 分发(0.6.34)
  • Oracle mysql-python连接器
  • Python 3.2
  • Windows 7 32/64(请注意,我安装了Python 32位)

问题是需要MySQLdb或Oursql,但我没有设法使它们中的任何一个正常工作.

找到了,但未能使其都无法正常工作. /p>

如果您知道其他适用于Python3的orm,我很感兴趣.

解决方案

我成功地使Oracle的python MySQL连接器与Python 3.3上的SQLAlchemy一起使用.您的连接字符串需要以"mysql + mysqlconnector://..."开头.更改连接字符串后,所有内容(简单的事情)开始起作用.

MySQL连接器文档可在以下位置找到: https://dev.mysql. com/doc/connector-python/en/

该软件包位于PyPi上: https://pypi.org/project/mysql- connector-python/

以下是有关使用Python连接器的SQLAlchemy文档: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector

Currently:

  • SQLAlchemy installed and working (or at least import v0.8.0b2)
  • Mysql (v5.5.16)
  • Distribute (0.6.34)
  • Oracle mysql-python connector
  • Python 3.2
  • Windows 7 32/64 (note that I installed Python 32bits)

The problem is that MySQLdb or Oursql is required and I didn't managed to get any of them working.

Found this but didn't manage to get it working neither.

Edit: If you are aware of an other orm that works with Python3, I'm interested.

解决方案

I was successful in getting Oracle's MySQL connector for python working with SQLAlchemy on Python 3.3. Your connection string needs to start with "mysql+mysqlconnector://...". After I changed my connection string everything (well, simple things) started working.

The MySQL connector docs can be found here: https://dev.mysql.com/doc/connector-python/en/

The package is up on PyPi: https://pypi.org/project/mysql-connector-python/

Here are the SQLAlchemy docs about using the Python connector: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqlconnector

这篇关于通过SQLAlchemy的Python 3和mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆