Unable to install mysqlclient on centos

前端 未结 5 2082
别跟我提以往
别跟我提以往 2021-01-14 05:36

I am building a django app and for which i need to configure mysql.I am trying to install mysqlclient module for sql connection and this is what i am trying

         


        
5条回答
  •  隐瞒了意图╮
    2021-01-14 06:31

    Solved in CentOS 7 + MariaDB 10.2

    I'm having same issue, and I would like to contribute with my answer. I've just installed in my 2 servers running CentOS 7 with MariaDB (10.2.14-MariaDB MariaDB Server) .

    $ cat /etc/centos-release
    CentOS Linux release 7.4.1708 (Core)
    
    $ mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is XXXX
    Server version: 10.2.14-MariaDB MariaDB Server
    

    I've installed MariaDB, this packages:

    $ yum list installed | grep mariadb
    MariaDB-client.x86_64                   10.3.13-1.el7.centos           @mariadb
    MariaDB-common.x86_64                   10.3.13-1.el7.centos           @mariadb
    MariaDB-compat.x86_64                   10.3.13-1.el7.centos           @mariadb
    MariaDB-server.x86_64                   10.3.13-1.el7.centos           @mariadb
    galera.x86_64                           25.3.25-1.rhel7.el7.centos     @mariadb
    

    I found that the problem is that mysqlclient requires mysql-devel packages, which is different from mariadb-devel. Don't install mariadb-devel!

    So, to install only mysql-devel, you need to:

    1. Remove any MariaDB-devel

    $ sudo yum erase MariaDB-devel.x86_64
    

    2. Add MySQL repository in yum

    1. Go to https://dev.mysql.com/downloads/repo/yum/ and select the RPM file for your CentOS (for me, I choose "Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package". Click "download".)
    2. Download without registration, copy bottom link "No thanks, just start my download".
    3. Go to your terminal and type:
    $ wget link-to-rpm-you-choose
    
    1. After download complete, type:
    $ sudo rpm -Uvh your-rpm-downloaded
    

    3. Now, install mysql-devel

    1. Type (this is my version, watch yours):
    $ sudo yum install mysql-community-devel.x86_64
    

    4. Now, finally: mysqlclient

    1. Type:
    $  sudo pip install mysqlclient
    Collecting mysqlclient
      Cache entry deserialization failed, entry ignored
      Cache entry deserialization failed, entry ignored
      Downloading https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz (85kB)
        100% |████████████████████████████████| 92kB 758kB/s
    Installing collected packages: mysqlclient
      Running setup.py install for mysqlclient ... done
    Successfully installed mysqlclient-1.4.2.post1
    You are using pip version 8.1.2, however version 19.0.3 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    
    

    And that's it! It worked like a charm and now I can use Python + Django + MariaDB/MySQL

    Oh, and mysqlclient is the connector recommended by Django. See: https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers

    Good luck and see ya! :-)

提交回复
热议问题