本篇内容主要讲解“Python如何安装mariadb对应的MySQLdb扩展”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python如何安装mariadb对应的MySQLdb扩展”吧!
debian下安装
比如网上的方案是:
apt-get install libmysql-devapt-get install libmysqlclient-devapt-get install python-devpip install mysqlclient
这些命令一般情况下是没问题的,但是本机上安装的是maraidb,那就扯淡了
MariaDB [(none)]> select version();+--------------------------+| version() |+--------------------------+| 10.1.38-MariaDB-0+deb9u1 |+--------------------------+
搜索apt的源发现没有相应的libmysql-dev 之类的,搜索如下:
ljf@ljf:/var/www/python$ sudo apt-cache search libmysqllibglpk40 - linear programming kit with integer (MIP) supportlibcrypt-mysql-perl - Perl module to emulate the MySQL PASSWORD() functionlibmysql-diff-perl - module for comparing the table structure of two MySQL databaseslibreoffice-base-drivers - Database connectivity drivers for LibreOfficesolr-common - Enterprise search server based on Lucene3 - common fileslibmariadbclient-dev-compat - MariaDB database development files (libmysqlclient compatibility)libmysql++-dev - MySQL C++ library bindings (development)libmysql++-doc - MySQL C++ library bindings (documentation and examples)libmysql++3v5 - MySQL C++ library bindings (runtime)libmysqlcppconn-dev - MySQL Connector for C++ (development files)libmysqlcppconn7v5 - MySQL Connector for C++ (library)libmysql-java - Java database (JDBC) driver for MySQLlibmysql-cil-dev - MySQL database connector for CLIlibmysql6.4-cil - MySQL database connector for CLIdefault-libmysqlclient-dev - MySQL database development files (metapackage)libmysql-ocaml - OCaml bindings for MySql (runtime package)libmysql-ocaml-dev - OCaml bindings for MySql (development package)node-mysql - MySQL client implementation for Node.js
搜索出来的源感觉不是那么对,但是有个源的名称叫:libmariadbclient-dev-compat ,那么会不会是要下载libmariadb的源文件呢,搜索下libmariadb对应的扩展看看:
ljf@ljf:/var/www/python$ sudo apt-cache search libmariadblibmariadbclient-dev - MariaDB database development fileslibmariadbclient-dev-compat - MariaDB database development files (libmysqlclient compatibility)libmariadbclient18 - MariaDB database client librarylibmariadbd-dev - MariaDB embedded database, development fileslibmariadbd18 - MariaDB embedded database, shared librarylibmariadb-dev - MariaDB Connector/C, development fileslibmariadb-dev-compat - MariaDB Connector/C, compatibility symlinkslibmariadb2 - MariaDB Connector/Cdefault-libmysqlclient-dev - MySQL database development files (metapackage)
果然libmariadb的源文件和推荐命令十分相似,安装试试:
apt-get install libmariadbd-devapt-get install libmariadbdclient-devapt-get install python-devpip install mysqlclient
执行完毕之后,测试:
ljf@ljf:/var/www/python$ pythonPython 2.7.13 (default, Sep 26 2018, 18:42:22)[GCC 6.3.0 20170516] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>> exit()
到此,相信大家对“Python如何安装mariadb对应的MySQLdb扩展”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!