Archive for the ‘MySql’ Category

MySQL 5.1.x, Python, OS X 10.6

September 28, 2009

Today I tried to get MySQL 5.1.39 (this version offers UUID_SHORT) working with Python. First you must uninstall mysql, mysqlb, and then issue the following commands:

$ which python
/opt/local/bin/python
$ python --version
Python 2.6.2
$ sudo port install mysql5-devel
$ sudo mysql_install_db5 --user=mysql
$ sudo /opt/local/bin/mysqld_safe5 --user=mysql&
$ /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-passwd'
$ ARCHFLAGS="-arch x86_64" python setup.py build
$ sudo python setup.py install
$ python
>>> import sys
>>> sys.path
# sys.path should print an entry with
# MySQL_python-1.2.3c1-py2.6-macosx-10.6-i386.egg'
>>> import MySQLdb
>>> MySQLdb.apilevel
'2.0'
>>> 

MySQL, Python on OS X – Snow Leopard

September 26, 2009

I was surprised at how much time I have spent on getting MySQL and Python to work on OS X Leopard. Here are the steps that worked for me.

  1. Install MySQL using mac port.
  2. Download the latest python mysqldb, build and install it.

To install latest MySQL (5.1.x) see this entry.
(more…)

How to log MySQL queries on OS X

July 30, 2008

The default MySQL installer for OS X also includes a startup item that is added to the Mac System Properties thru which you start and stop MySQL. For development purposes, I needed to be able to tail the query log. According to the documentation, you can pass –log=path-to-log-file to the startup script, or add a log entry to the [mysqld] section of /etc/my.cnf file. The latter is the easiest way of creating a query log on OS X. Here are the steps that you need to follow:

  1. Create the file /etc/my.cnf (if you already don’t have one) and add the following lines:
    [mysqld]
    log=/var/log/mysqld.log
  2. su (become root)
  3. cd /var/log
  4. touch mysqld.log
  5. chmod 777 /var/log/mysqld.log
  6. Restart MySQL
Now you should be able to tail -f /var/log/mysqld.log

JDBC Query Logging Parameters

February 16, 2008

Every once in while I need to log slow queries using the JDBC logging parameters and it always takes me a while to find this information. So here it is (line breaks for readability):


?profileSQL=true&
slowQueryThresholdMillis=100&
autoSlowLog=true&
explainSlowQueries=true&
gatherPrefMetrics=true&
logSlowQueries=true

Simply add the above parameters to your JDBC connection string.