Ramblings

May 31, 2010

Django OSX MySQL MAMP

Filed under: django, macports, mamp, mysql, mysqldb, osx — michaelangela @ 7:29 am

For my overly customized MAMP install, it wasn’t pretty. I forget why it’s actually set up this way now but the different parts didn’t like each other and it took quite a while to get it working. Not fun. But fortunately there were those who had gone before me and it wasn’t hard in the end. It just took a long time.

http://birdhouse.org/blog/2009/02/21/python-mysql-connections-on-mac-os/

http://www.marteinn.se/blog/?p=467

Correction. It just took a really REALLY long time. The reason? You need to have libs and headers and such in places that all make sense for everything to compile. (This is the SHORT version.) So MacPorts to the rescue. Install py25-mysql, copy some files around, use a slightly different “HOST” setting for the database connection and you’re good to go. But installing py25-mysql installs ALL the dependencies needed in order to get that running. Which is good when that’s what you need. Which is what took a long time. But at least it was a one command thing and not hopping all over the ‘net to find and install things as I was very close to doing.

And that bit about the unique “HOST” setting for mine turns out to be

DATABASE_HOST = ‘/Applications/MAMP_1.7.2/tmp/mysql/mysql.sock’

May 27, 2010

Ruby, OS X, MAMP, MySQL, do_mysql and getting it installed

Filed under: install, mysql, osx, ruby, tip — michaelangela @ 7:33 am

This took a lot of time. In hopes that this will help someone else, I add this link.

How to install the MySQL/Ruby gem on Mac OS X Leopard

Here’s the situation. I have MAMP. For legacy reasons my current MAMP 1.7.2 is in a custom directory. I use ruby. In particular I wanted to use DataMapper in a project with ruby. I wanted to use it with MySQL. That requires do_mysql. It just would not install with all kinds of errors. Well one in particular. It complained of possibly missing headers or libraries. After a long search the above link surfaced from the depths of Google. It almost worked for me. Everything but the last command actually. So for me, the command I ended up using is something like:

sudo env ARCHFLAGS=”-arch i386″ gem install mysql — –with-mysql-dir=/Applications/MAMP_1.7.2/Library –with-mysql-include=/Applications/MAMP_1.7.2/Library/include/mysql –with-mysql-config=/Applications/MAMP_1.7.2/Library/bin/mysql_config

This is OS X 10.5.8 Leopard

December 7, 2009

MYSQL database modeling and change management

Filed under: mysql, tool — michaelangela @ 12:23 pm

I currently use Navicat for MySQL to manage databases (especially nice for managing multiple sites via ssh). Change management is always an issue with snapshots being manually handled with data dumps. There are very helpful sync tools within Navicat but I’d like to try this to see if it helps the way I think it will. The partos of particular interest are the change management and, something I need to learn more of, forward engineering of a database.

MySQL :: MySQL Workbench 5.1

MySQL Workbench enables a DBA, developer, or data architect to visually design, generate, and manage all types of databases including Web, OLTP, and data warehouse databases. It includes everything a data modeler needs for creating complex ER models, and also delivers key features for performing difficult change management and documentation tasks that normally require much time and effort. MySQL Workbench is available on Windows, Linux and Mac OS.

July 6, 2008

Getting rid of the dreaded “can’t encode” errors with Python and MySQL and SqlSoup

Filed under: automation, cool, dev, mysql, python, sqlalchemy, sqlsoup, tip, xls — michaelangela @ 10:47 pm

So I was getting problems inserting data that has the ‘™’ symbol in it. Brutal stuff. Couldn’t find a way around it. Did it by hand in the end. Nasty. The problem was that I was getting

UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2122' in position 12: ordinal not in range(256)

where the '\u2122' is the ‘™’ symbol. There were some others as well. Finally happened upon this post which, fortunately, cleared it up. To use this tip with SqlSoup, the connection string needs a couple of extra parameters.

Instead of

db = SqlSoup('mysql://user:password@host:port/database')

use

db = SqlSoup('mysql://user:password@host:port/database?charset=utf8&use_unicode=0')

The requirement of course is that the database tables are set up with the UTF-8 charset.

But now I can thrash data at will! Mwahahahaha! Sorry… but now I can pull in unicode data from an Excel file and throw it into a database with rediculous ease. OK not rediculous ease but wow this simplifies it.

[edit]I like to use iPython to do my data thrashing with SqlSoup and SqlAlchemy. If you use the second connection string with the charset and use_unicode options, don’t reset the db connection to the previous one without those. Once doing that I couldn’t set it back and had to exit and restart the session. Bummer.[/edit]

mysql unicode issues – sqlalchemy | Google Groups

a. have use_unicode=0, set charset=’utf8′ on the connection, AND

b. ensure you have
table options = {‘mysql_charset’: ‘utf8’} when creating tables, and
all should be well.

Blog at WordPress.com.