Unable to install mysqlclient on centos

前端 未结 5 2083
别跟我提以往
别跟我提以往 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:10

    The simplest solution that worked for me is:

    yum install python-devel mysql-devel
    

    Then install mysqlclient using pip

    pip install mysqlclient
    
    0 讨论(0)
  • 2021-01-14 06:11

    I found this solution at https://github.com/r-dbi/RMySQL/issues/197:

    I think this is a bug in that custom MariaDB repo. Their package MariaDB-devel-10.2.6-1.fc25.x86_64 only contains a library named:

    /usr/lib64/libmariadbclient.a
    

    However their pkg-config yields another name:

    > pkg-config --libs mariadb
        -lmariadb
    

    You best raise this at the maintainers of that repo. A workaround is to symlink libmariadbclient.a to libmariadb.a:

    sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
    

    That fixes the installation.

    So basically to have mysqlclient install in Python 3.6 and CentOS 7 you need to run:

    sudo yum install -y python36-devel mysql-devel gcc
    
    sudo ln -s /usr/lib64/libmariadbclient.a /usr/lib64/libmariadb.a
    
    pip install mysqlclient
    
    0 讨论(0)
  • 2021-01-14 06:25

    Open the terminal or login to the workstation/laptop/dev-server using ssh client. Type the following command yum command as a root user:

    # yum install mysql
    Loaded plugins: downloadonly, fastestmirror, security
    Loading mirror speeds from cached hostfile
     * base: mirror.wiredtree.com
     * extras: mirrors.serveraxis.net
     * updates: bay.uchicago.edu
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package mysql.x86_64 0:5.1.71-1.el6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package         Arch             Version                  Repository      Size
    ================================================================================
    Installing:
     mysql           x86_64           5.1.71-1.el6             base           893 k
    
    Transaction Summary
    ================================================================================
    Install       1 Package(s)
    
    Total download size: 893 k
    Installed size: 2.4 M
    Is this ok [y/N]: y
    Downloading Packages:
    mysql-5.1.71-1.el6.x86_64.rpm                            | 893 kB     00:00     
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : mysql-5.1.71-1.el6.x86_64                                    1/1 
      Verifying  : mysql-5.1.71-1.el6.x86_64                                    1/1 
    
    Installed:
      mysql.x86_64 0:5.1.71-1.el6                                                   
    
    Complete!
    

    mysql client the basic syntax is:

    mysql -u USER-NAME-HERE -h MYSQL-DB-SERVER-IP-ADDRESS-HERE -p DB-NAME
    mysql -u nixcraft -h server1.cyberciti.biz -p salesdata
    
    0 讨论(0)
  • 2021-01-14 06:30

    It's complaining about not being able to find mariadb libs. Run the following to find out why:

    ld -lmariadb --verbose
    

    This should tell you specifically what gcc is missing.

    My guess is that you are missing some MySQL development headers. Install them with:

    debian / ubuntu: sudo apt-get install python-dev libmysqlclient-dev
    redhat / centos: sudo yum install python-devel mysql-devel
    

    Update: It really is missing MariaDB shared libs. I think on CentOS, this should take care of it:

    sudo yum install MariaDB-devel
    

    Final Update: Just use PyMySQL - pure python, no headers required, no need to jump through these kinds of hoops.

    0 讨论(0)
  • 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! :-)

    0 讨论(0)
提交回复
热议问题