Unable to install python mysqlclient - OSError: mysql_config not found
I found this answer on StackOverflow titled: How to use MYSql from xampp for python 3?.
An answer there shows 3 ways to install the Python drivers/connectors for working with MySQL DBs.
method 1 - MySQL-python
To install the MySQL-python package, type the following command:
$ pip install MySQL-python
Method 2 - mysql-connector-python
To install the mysql-connector-python package, type the following command:
$ pip install mysql-connector-python
Method 3 - pymysql
To install the pymysql package, type the following command:
$ pip install pymysql
Examples
$ cat mysql_connector_exs.py
hostname = 'localhost'
username = 'USERNAME'
password = 'PASSWORD'
database = 'DBNAME'
def doQuery( conn ) :
cur = conn.cursor()
cur.execute( "SELECT fname, lname FROM employee" )
for firstname, lastname in cur.fetchall() :
print firstname, lastname
print "Using MySQLdb…"
import MySQLdb
myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()
print "Using pymysql…"
import pymysql
myConnection = pymysql.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()
print "Using mysql.connector…"
import mysql.connector
myConnection = mysql.connector.connect( host=hostname, user=username, passwd=password, db=database )
doQuery( myConnection )
myConnection.close()