Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Python MySQLdb module using pip?

Tags:

python

mysql

pip

How can I install the MySQLdb module for Python using pip?

like image 236
Marian Avatar asked Sep 16 '14 09:09

Marian


People also ask

What is MySQLdb module in Python?

MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API.

What is import MySQLdb?

First off, import MySQLdb is used to import the required python module. MySQLdb. connect() method takes hostname, username, password, and database schema name to create a database connection. On successfully connecting with the database, it will return a connection object (which is referred to as dbconnect here).


1 Answers

It's easy to do, but hard to remember the correct spelling:

pip install mysqlclient 

If you need 1.2.x versions (legacy Python only), use pip install MySQL-python

Note: Some dependencies might have to be in place when running the above command. Some hints on how to install these on various platforms:

Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)

sudo apt-get install python-pip python-dev libmysqlclient-dev 

Fedora 24:

sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc 

Mac OS

brew install mysql-connector-c 

if that fails, try

brew install mysql 
like image 125
Marian Avatar answered Sep 29 '22 12:09

Marian