Setting up MySQL with Python ( or Django ) can be a bit tricky since no database driver is officially provided by MySQL (as of Feb 2011). I had a couple of failed attempts, but finally got it working. A hit and trial method and troubleshooting guides from various websites helped. To sum it up, here is what worked for me:
Environment:
- Mac OS X 10.6.6
- Python 2.6.1 (Django supports this version and is installed on Mac by default if Xcode is installed)
- GCC 4.2.1
- MySQLdb 1.2.3 (Download from http://sourceforge.net/projects/mysql-python/)
- MySQL 5.1.x Server (Since MySQLdb supports upto this version as of Feb 2011)
Don't try to reuse the MySQL installed as part of MAMP because it doest match typical deployment environments if you would use Python/Django for professional application and secondly its overtly complicated.
Install MySQL:
See previous post Install/Uninstall MySQL 5.1 on Mac @ http://abhishekdev.posterous.com/installuninstall-mysql-51-on-mac
Perquisites: before installing MySQLdb
- Add the following line to the ~/.bash_profile or ~/.profile (Found by default on10.6.x) file under the User Home (if ~ is not known to you)
PATH="${PATH}:/usr/local/mysql/bin" - Type in Terminal
mysql --version
Should read something similar to "mysql Ver 14.14 Distrib 5.1.55, for apple-darwin10.3.0 (i386) using readline 5.1"
Install MySQLdb:
- Extract MySQLdb if it came archived/compressed
- Open Terminal
- Make the extracted folder as current working directory
cd [Path if any]MySQL-python-1.2.3
- Type in Terminal
python setup.py build sudo python setup.py install
- If no Errors get thrown. In Python Prompt type "import MySQLdb"
python import MySQLdb
Posted via email from Abhishek Dev
No comments:
Post a Comment