How to use MYSql from xampp for python 3?

Question:

I am getting below error when I try to install MySQL client using the command “pip3 install mysqlclient”.

Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup.py", line 18, in <module>
        metadata, options = get_config()
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup_posix.py", line 53, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/l1/f1klm_s92g53c9v2p1vrdwg80000gn/T/pip-install-a0t6svmj/mysqlclient/setup_posix.py", line 28, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found

XAMPP version:- 7.2.3.0
Python:- 3.7

Can anybody help me to solve this error? Thanks

Asked By: Deep Shah

||

Answers:

To install the MySQL-python package, type the following command:

pip install MySQL-python

To install the mysql-connector-python package, type the following command:

pip install mysql-connector-python

To install the pymysql package, type the following command:

pip install pymysql

Code sample

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()
Answered By: bugfreerammohan

Ensure you have at least tried these commands.

  • pip install mysql
  • export PATH=$PATH:/usr/local/mysql/bin
  • pip install MySQL-Python
  • Commands are run a root or sudo.

If nothing has changed. One of these solutions might help:

  1. Try running which mysql_config from bash. If it can’t be found, run: locate mysql_config. The file path to the binary needs to be in the $PATH environment variable or specified in setup.py for the (what is now) missing module.

  2. You could try installing different packages. There is: mysql-connector-python or libmysqlclient-dev. The python-dev might help.

  3. Attempt to find the directory and files mysql/bin, mysql_config, and MySQL-Python and add their locations to $PATH.

EDIT: There are a couple solutions to try:

  • apt-get install python-mysqldb
  • Debian/Ubuntu: sudo apt-get install libmysqlclient-dev
  • Debian/Ubuntu (2018): sudo apt install default-libmysqlclient-dev
  • XAMPP (OP specified): export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin
Answered By: Noah M.

I have M1 processor in mac, and it solves my problem:

Install brew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install mysql with brew: arch -arm64 brew install mysql

Try install again with pip install mysql

Answered By: natielle