django安装mysql驱动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django安装mysql驱动相关的知识,希望对你有一定的参考价值。

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

以上是关于django安装mysql驱动的主要内容,如果未能解决你的问题,请参考以下文章

3.django连接mysql数据库及安装mysqldb驱动报错解决办法

Django 第八课 2.MySQL相关软件

42.MySQL数据库安装,及驱动程序选择

关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段

python测试开发django-10.django连接mysql

Python基础之 Django模型