================================================================
-> MySQL Server and Python connector(Mac OS X Snow Leopard):
================================================================
Here goes some tricky stuff. You may want to consider getting yourself a cup of
linden infusion :-P
--> If you have a previous MySQL version:
If you have a previous MySQL version, perhaps a 32 bit one, you may encounter several
problems to perform the upgrade to a newer, 64-bit version. But don't worry, the
following steps should get you going in no time.
Hands on!
To uninstall the previous version, do this *in order*:
- First you need to go to: /Library/Receipts and look for a file named
'InstallHistory.plist' (It's just a regular property list)
- Open it and look for the entries regarding MySQL, and delete them.
MacBookPro:~ matias$ cd /Library/Receipts/
MacBookPro:Receipts matias$ sudo nano InstallHistory.plist
ctrl+shift+w, look for the entries regarding MySQL and delete them.
ctrl+o (save) ctrl+x (exit)
- As the installer receipts are actually located in a different place on Snow Leopard:
MacBookPro:Receipts matias$ cd /private/var/db/receipts/
MacBookPro:receipts matias$ ls *mysql*
com.mysql.mysql.bom com.mysql.mysqlstartup.bom
com.mysql.mysql.plist com.mysql.mysqlstartup.plist
MacBookPro:receipts matias$ sudo rm *mysql*
- Now we are ready to do the uninstall work per se, by doing these *in order*:
* Use mysqldump or MySQL Admin to backup your databases to text files!
* Stop the database server
* sudo rm /usr/local/mysql
* sudo rm -rf /usr/local/mysql*
* sudo rm -rf /Library/StartupItems/MySQLCOM
* sudo rm -rf /Library/PreferencePanes/My*
* edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
* rm -rf ~/Library/PreferencePanes/My*
* sudo rm -rf /Library/Receipts/mysql*
* sudo rm -rf /Library/Receipts/MySQL*
* sudo rm /etc/my.cnf
--> Install MySQL (server, startup item, pref pane):
- Install mysql's x86_64 version from the .dmg file. Download the .dmg from
here: http://dev.mysql.com/downloads/mysql/5.1.html#downloads
(I also put the installers under '3rdparty/MacOSX_Installers' folder).
--> Install MySQLdb in the virtualenv
- Turn the virtualenv on. This command does the trick:
MacBookPro:~ matias$ laexpo_start
(Env)MacBookPro:~ matias$
- Fetch MySQL-python-1.2.3 from here: http://sourceforge.net/projects/mysql-python/.
I'll assume you downloaded the .tar.gz file to the Desktop.
- Unpack the tarball, enter the folder:
(Env)MacBookPro:~ matias$ tar xzf MySQL-python-1.2.3.tar.gz
(Env)MacBookPro:~ matias$ cd MySQL-python-1.2.3
- Open the 'site.cfg' file and edit the 'mysql_config' to poin to the path where
you mysql_config resides. For me it is '/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config'
- Open the 'setup_posix.py' file and set the 'mysql_config.path' to the same path
you did in the previous step(line 26). Should end up looking like this:
mysql_config.path = "/usr/local/mysql-5.1.50-osx10.6-x86_64/bin/mysql_config"
- Compile the thing:
(Env)MacBookPro:~ matias$ cd ~/Desktop/MySQL-python-1.2.3
(Env)MacBookPro:MySQL-python-1.2.3 matias$ python setup.py clean
(Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' /usr/bin/python setup.py build
(Env)MacBookPro:~ matias$ ARCHFLAGS='-arch x86_64' python setup.py install
* NOTE 1: It is critical to have the virtualenv activated before running the above
listed command. If it is not, the installation of MySQLdb will be done in
the system and no in the virtualenv and therefore MySQLdb will not be
available when you turn the virtualenv on.
* NOTE 2: It is also critical to set the compilation flags correctly. If not set
correctly, the compilation will default to 32-bit architecture and will
not work afterwards with MySQL.
* NOTE 3: DON'T USE 'sudo' FOR THE COMPILLATION/INSTALL COMMANDS. If you do so, you'll
be installing MySQLdb to the system and not to the virtualenv.
- Confirm the process worked ok:
(Env)MacBookPro:MySQL-python-1.2.3 matias$ python
Python 2.6.1 (r261:67515, Dec 17 2009, 00:59:15)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.version_info
(1, 2, 3, 'final', 0)
3 comentarios:
This is awesome. Great work! Works perfectly, really smooth.
Thanks for sharing!
Pedro
PmDesign
You're welcome!
So nice to hear it worked for you and save you time and hassle :)
thanks a lot is very usefully, finaly get MySQL with Python :-)
Publicar un comentario