本来安装MySQLdb
的帖子多如过江之鲤鱼,实在是数不胜数,奈何他们服务器上安装的都是mysql
,而现在的新服务器,默认下载安装的都是mariadb
,所以这篇文章主要记录一下如何安装mariadb
对应的MySQLdb
扩展。
本来以为linux
下直接pip install
就能下载了,但是实际操作的时候要是要注意的。
比如网上的方案是:
apt-get install libmysql-dev
apt-get install libmysqlclient-dev
apt-get install python-dev
pip 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 libmysql
libglpk40 - linear programming kit with integer (MIP) support
libcrypt-mysql-perl - Perl module to emulate the MySQL PASSWORD() function
libmysql-diff-perl - module for comparing the table structure of two MySQL databases
libreoffice-base-drivers - Database connectivity drivers for LibreOffice
solr-common - Enterprise search server based on Lucene3 - common files
libmariadbclient-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 MySQL
libmysql-cil-dev - MySQL database connector for CLI
libmysql6.4-cil - MySQL database connector for CLI
default-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 libmariadb
libmariadbclient-dev - MariaDB database development files
libmariadbclient-dev-compat - MariaDB database development files (libmysqlclient compatibility)
libmariadbclient18 - MariaDB database client library
libmariadbd-dev - MariaDB embedded database, development files
libmariadbd18 - MariaDB embedded database, shared library
libmariadb-dev - MariaDB Connector/C, development files
libmariadb-dev-compat - MariaDB Connector/C, compatibility symlinks
libmariadb2 - MariaDB Connector/C
default-libmysqlclient-dev - MySQL database development files (metapackage)
果然libmariadb
的源文件和推荐命令十分相似,安装试试:
apt-get install libmariadbd-dev
apt-get install libmariadbdclient-dev
apt-get install python-dev
pip install mysqlclient
执行完毕之后,测试:
ljf@ljf:/var/www/python$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> exit()
成功引入无报错,则代表正常安装MySQLdb
,记录一下。
咳咳,实不相瞒,这篇文章主要是为了凑数,为了1024勋章,冲鸭!!!
end