如何在 Windows 上的 Python 3 中连接到 MySQL?

2021-11-20 00:00:00 python python-3.x mysql

我在 Windows 上使用 ActiveState Python 3 并想连接到我的 MySQL 数据库.我听说 mysqldb 是用.我找不到 Python 3 的 mysqldb.

mysqldb 的二进制文件是否存在可用的存储库?如何在 Windows 上的 Python 3 中连接到 MySQL?

解决方案

目前有几个选项可以将 Python 3 与 mysql 结合使用:

https://pypi.python.org/pypi/mysql-connector-python

  • Oracle 官方支持
  • 纯蟒蛇
  • 有点慢
  • 与 MySQLdb 不兼容

https://pypi.python.org/pypi/pymysql

  • 纯蟒蛇
  • 比 mysql-connector 更快
  • 几乎完全兼容MySQLdb,调用pymysql.install_as_MySQLdb()

https://pypi.python.org/pypi/cymysql

  • pymysql 的 fork,带有可选的 C 加速

https://pypi.python.org/pypi/mysqlclient

  • Django 推荐的库.
  • 原 MySQLdb 的友好分叉,希望有一天能合并回来
  • 最快的实现,因为它基于 C.
  • 与 MySQLdb 最兼容,因为它是一个分支
  • Debian 和 Ubuntu 使用它来提供 python-mysqldbpython3-mysqldb 包.

此处的基准:https://github.com/methane/mysql-driver-benchmarks

I am using ActiveState Python 3 on Windows and wanted to connect to my MySQL database. I heard that mysqldb was the module to use. I can't find mysqldb for Python 3.

Is there a repository available where the binaries exist for mysqldb? How can I connect to MySQL in Python 3 on Windows?

解决方案

There are currently a few options for using Python 3 with mysql:

https://pypi.python.org/pypi/mysql-connector-python

  • Officially supported by Oracle
  • Pure python
  • A little slow
  • Not compatible with MySQLdb

https://pypi.python.org/pypi/pymysql

  • Pure python
  • Faster than mysql-connector
  • Almost completely compatible with MySQLdb, after calling pymysql.install_as_MySQLdb()

https://pypi.python.org/pypi/cymysql

  • fork of pymysql with optional C speedups

https://pypi.python.org/pypi/mysqlclient

  • Django's recommended library.
  • Friendly fork of the original MySQLdb, hopes to merge back some day
  • The fastest implementation, as it is C based.
  • The most compatible with MySQLdb, as it is a fork
  • Debian and Ubuntu use it to provide both python-mysqldb andpython3-mysqldb packages.

benchmarks here: https://github.com/methane/mysql-driver-benchmarks

相关文章