温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

django安装mysql驱动

发布时间:2020-07-31 15:16:18 来源:网络 阅读:2375 作者:sharonaa 栏目:软件技术

django目前支持三种mysql驱动来进行mysql的链接

  • MySQLdb is a native driver that has been developed and supported for over a decade by Andy Dustman.

  • mysqlclient is a fork of MySQLdb which notably supports Python 3 and can be used as a drop-in replacement for MySQLdb. At the time of this writing, this is the recommended choice for using MySQL with Django.

  • MySQL Connector/Python is a pure Python driver from Oracle that does not require the MySQL client library or any Python modules outside the standard library.


mysqldb 目前不支持python3+,推荐使用mysqlclient

尝试了在pycharm上直接安装mysqlclient,报以下错误:OSError: mysql_config not found


在git上查阅安装步骤:

Prerequisites

You may need to install the Python and MySQL development headers and libraries like so:

sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu

sudo yum install python-devel mysql-devel # Red Hat / CentOS

On Windows, there are binary wheel you can install without MySQLConnector/C or MSVC.

Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command :

sudo apt-get install python3-dev # debian / Ubuntu

sudo yum install python3-devel # Red Hat / CentOS

brew install mysql-connector-c # macOS (Homebrew)

Install from PyPI

pip install mysqlclient

因为我在mac上,使用的python3,故先执行命令:

brew install mysql-connector-c 


然后再执行:

pip3 install mysqlclient

报如下错误:

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-m9v70gan/mysqlclient/

这个地方有点疑惑:使用pip3命令后,最终调用的是python,而不是python3


查看mysqlclient的源代码,发现根本原因还是因为没找到mysql_config,明白过来需要安装mysql,才能正常安装mysqlclient


Installed /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mysqlclient-1.3.10-py3.6-macosx-10.6-intel.egg

Processing dependencies for mysqlclient==1.3.10

Finished processing dependencies for mysqlclient==1.3.10


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI