Python --Install MySQLDB on EC2

Ref: [1] - Problem with installing ‘MySQLdb’ in Python [2] - Stackoverflow - How to install MySQLdb (Python data access library to MySQL) on Mac OS X? [3] - Python MySQL for EC2 Amazon AMI

Since the version of MySQLDB was changing in the old days, the instructions about how to install this useful tool varies a lot, which makes this tool is very hard to install.

Among all these instructions I found, I find they are not for the current version of MySQLDB. And some steps mentioned by these instructions are not necessary.

So I'm just going to give my install procedure. Hope it will help someone.

The MySQLDB I'm using is the MySQL-python-1.2.4b4.

Step 1

Make sure you have install gcc, mysql-devel and of cource mysql. If not, follow this post.

Step 2

Although most EC2 instance will be with python, but still you will need python-devel.

yum install python-devel

Note that this may need admin user.

Step 3

Download the source code to some place you can easily access to, and unzip it:

url -O http://jaist.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz
tar -xzvf MySQL-python-1.2.4b4.tar.gz

Go into the dir you just unzipped, install it directly:

python setup.py build
python setup.py install

It should be done by now. You could check by

import MySQLdb

in the python console.


The procedure could be a little different according how you set up your EC2 instance, but the most tricky part, I believe, is installing python-devel before you install the MySQLdb.

To sum up, before you install MySQLdb, make sure you have below all intalled:

Recommended Posts

Python --Install MySQLDB on EC2
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
Install Python 3 on Mac
Install Python3.4 on CentOS 6.6
Install python on windows
Install Python 2.7.3 on CentOS 5.4
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Install Python 3.8, Pip 3.8 on EC2 (Amazon Linux 2)
Install Python 3.6 on Docker
[2020 version] How to install Python3 on AWS EC2
Install watchdog on Windows + Python 3.3
Install pygame on python3.4 on mac
Install Python 3.8 on CentOS 7 (SCL)
Install pandas 0.14 on python3.4 [on Mac]
Install OpenCV on Ubuntu + python
Install Python 3.8 on CentOS 8 (AppStream)
[Python] [Chainer] [Windows] Install Chainer on Windows
install python
Install Python Pillow on Amazon Linux
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Python3 on Sakura server (FreeBSD)
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install xgboost (python version) on Windows
Install Python on Windows + pip + virtualenv
Install Python 3.7 Anaconda on MAC, but Python 2
Install python3 on Mac (El Capitan)
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install Python development environment on Windows 10
Install Python on CentOS using Pyenv
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
Steps to install python3 on mac
Install Python on CentOS using pyenv
I'll install Ruby on EC2 (Amazon Linux2) 2020
Python on Windows
[Kivy] How to install Kivy on Windows [Python]
Install python library on Lambda using [/ tmp]
Install Python locally
Steps to install Python environment on Ubuntu
Install NAOqi python
scipy stumbles with pip install on python 2.7.8
python on mac
Install Python less than 3.5.3 on macOS Catalina
Install Python Control
Install python on xserver to use pip
Python on Windbg
Install Python3 on mixhost server [Currently NG]
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
CentOS8 --Install --Python3
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Install and run Python3.5 + NumPy + SciPy on Windows 10
Install Python3, numpy, pandas, matplotlib, etc. on Windows
Build python environment with pyenv on EC2 (ubuntu)
Install python package in personal environment on Ubuntu
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Python development on Ubuntu on AWS EC2 (using JupyterLab)
Run pip install on MacOS Python 3.7 or later
Install Python 3 on MacOS Catalina (with Homebrew only)