Installing mysql-python on Centos

前端 未结 5 1581
逝去的感伤
逝去的感伤 2020-12-03 01:45

I\'m trying to get the MySQL-python lib installed on centos 5.5. I ran

sudo yum install MySQL-python

but then when I tried:



        
相关标签:
5条回答
  • 2020-12-03 02:10

    I have Python 2.7.5, MySQL 5.6 and CentOS 7.1.1503.

    For me it worked with the following command:

    # pip install mysql-python
    

    Note pre-requisites here:

    Install Python pip:

    # rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
    
    # yum -y update
    Reboot the machine (if kernel is also updated)
    
    # yum -y install python-pip
    

    Install Python devel packages:

    # yum install python-devel
    

    Install MySQL devel packages:

    # yum install mysql-devel
    
    0 讨论(0)
  • 2020-12-03 02:11

    You probably did not install MySQL via yum? The version of MySQLDB in the repository is tied to the version of MySQL in the repository. The versions need to match.

    Your choices are:

    1. Install the RPM version of MySQL.
    2. Compile MySQLDB to your version of MySQL.
    0 讨论(0)
  • 2020-12-03 02:16

    mysql-python NOT support Python3, you may need:

    sudo pip3 install mysqlclient
    

    Also, check this post for more alternatives.

    0 讨论(0)
  • 2020-12-03 02:30

    For centos7 I required: sudo yum install mysql-devel gcc python-pip python-devel sudo pip install mysql-python

    So, gcc and mysql-devel (rather than mysql) were important

    0 讨论(0)
  • 2020-12-03 02:31

    Step 1 - Install package

    # yum install MySQL-python
    Loaded plugins: auto-update-debuginfo, langpacks, presto, refresh-packagekit
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package MySQL-python.i686 0:1.2.3-3.fc15 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package              Arch         Version                 Repository      Size
    ================================================================================
    Installing:
     MySQL-python         i686         1.2.3-3.fc15            fedora          78 k
    
    Transaction Summary
    ================================================================================
    Install       1 Package(s)
    
    Total download size: 78 k
    Installed size: 220 k
    Is this ok [y/N]: y
    Downloading Packages:
    Setting up and reading Presto delta metadata
    Processing delta metadata
    Package(s) data still to download: 78 k
    MySQL-python-1.2.3-3.fc15.i686.rpm                       |  78 kB     00:00     
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : MySQL-python-1.2.3-3.fc15.i686                               1/1 
    
    Installed:
      MySQL-python.i686 0:1.2.3-3.fc15                                              
    
    Complete!
    

    Step 2 - Test working

    import MySQLdb
    db = MySQLdb.connect("localhost","myusername","mypassword","mydb" )
    cursor = db.cursor()
    cursor.execute("SELECT VERSION()")
    data = cursor.fetchone()    
    print "Database version : %s " % data    
    db.close()
    

    Ouput:

    Database version : 5.5.20 
    
    0 讨论(0)
提交回复
热议问题