Skip to content
Jasleen Kaur edited this page Jan 8, 2016 · 6 revisions

Requirements

  • Python 3 and headers (packages: python3 and python3-dev)
  • mysql_config utility along with MySQL headers (libmysqlclient-dev package)
  • compiler and linker
  • Optionally MySQL for Python 3 tarball

(MySQL server nor client aren't required, in case your MySQL server are on another machine)

Step by step

  • Install Python 3 and also Python 3 headers sudo apt-get install python3 python3-dev
  • check if python3 works
  • install libmysqlclient-dev package and it's dependencies. which will contain mysql_config and MySQL headers. Also as dependencies gcc will be installed. sudo apt-get install libmysqlclient-dev

You can install it directly from git with pip3

pip3 install git+git://github.com/davispuh/MySQL-for-Python-3

Or manually

  • download MySQL for Python 3 tarball
  • extract it
  • and now finally install it with python3 setup.py install
  • can test if it was successfully installed by opening python3 and import MySQLdb

Basic check

  1. install MySQL server sudo apt-get install mysql-server
  2. create test.py with contents from [Usage example](Usage example)
  3. edit settings (root password, etc) accordingly
  4. try it with python3 test.py

Note

apt-get is for Debian, Ubuntu distributions, if you've Fedora or CentOS then use yum. Different for others.

Clone this wiki locally