HOWTO enable the query log on MySQL on Mac OS X

Tailing the MySQL query log in real time can be a lifesaver for any developer, and it’s pretty easy to do.

1. Make the logfile

Create the logfile that the mysqld process will write to.

If you’re using MacPorts or the MySQL package, run this on the terminal:

sudo touch /var/log/mysql-query.log
sudo chown _mysql /var/log/mysql-query.log

If you’re using homebrew, MySQL will be running with your user id, so you’ll want to:

sudo touch /var/log/mysql-query.log
sudo chown `whoami` /var/log/mysql-query.log

2. Tell MySQL to write to the logfile

If you’ve installed MySQL 5.1.x from the Mac .pkg, you won’t have an /etc/my.cnf, but it just needs to have these two lines:

[mysqld]
log=/var/log/mysql-query.log

3. Restart mysqld

If you have the MySQL preference pane, open that, click stop, then start. (It turns out that when the preference pane is open, it pings the database every 2 seconds, so it can detect if the db is alive. If you mangle the my.cnf, you’ll find the start button seems to not respond to clicks.)

If you installed MySQL with homebrew or MacPorts, and installed a launchd script to start MySQL on startup, you can run mysqladmin shutdown and launchd will restart MySQL for you.

4. Finally: watch the query log

Run tail -f /var/log/mysql-query.log

Set up JAVA_HOME to track Java Preferences.app on Mac OS X

/Applications/Utilities/Java Preferences.appMac OS X’s Java Preferences.app has a pane for switching between versions of the JDK, but I just found out from a coworker (thanks, Mike!) that you can make your shell match that preference easily — just add this to your ~.bashrc:

export JAVA_HOME=$(/usr/libexec/java_home)

If you change your JDK priority preference, you’ll need to re-source your ~/.bashrc or just open a new terminal window.

Speed up Firefox!

My Firefox on Mac was getting pretty lethargic — almost a minute to spin up, and multiple seconds to just open a new tab. I installed the new beta of Google Chrome, and remembered how nice a speedy browser was.

Google Chrome for Mac is a nice first effort, but without custom search engines, and all the other firefox add-ons, the shininess gets pretty tarnished. I needed my fast firefox back!

I made just a couple changes, though, and my Firefox is back to it’s prior speedy self!

Continue reading

Download Xcode 3.1.4 for Leopard

Apple’s developer website only links to the latest version of Xcode, which requires Snow Leopard (Mac OS X 10.6).

If you’re still running Leopard (10.5), go to this link after logging in with your ADC credentials:

http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/9.1.17.2.1.3.3.1.0.1.1.0.3.3.3.3.1

Search for “3.1.4″ — it’s 1/3 down the page. You might also want to check the wikipedia list of xcode versions to see if 3.1.4 is still the latest version.

(reference)

(November 2010 update: Apple’s URL changed)

Apache2, PHP, and MySQL on Mac OS X using MacPorts

1. Install MacPorts

Follow the instructions here: http://www.macports.org/install.php.

2. Install apache2

sudo port install apache2

Note that the macports instructions suggest installing the launchctl script now, but we’ll do that after mysql and php are installed.

3. Install and configure MySQL

If you want 5.0.x, use mysql5-server. If you need 5.1.x, install mysql5-server-devel (at least as of August 2009).

sudo port install mysql5-server

As the macports instructions state,

In order to setup the database, you might want to run sudo -u mysql mysql_install_db5 if this is a new install.

It’s never a bad idea to set the root password, and as the document suggests, run:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'

You also want to install a database configuration file — there are a bunch of templates in /opt/local/share/mysql5/mysql/, but for development, my-small.cnf should suffice:

sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf

Once the config is in place, spin up mysql:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Check that mysql is up and running by connecting with the mysql client:

mysql -h localhost -u root -p

4. Fix your PATH

Note that the mysql binaries in /opt/local/bin all have a “5″ suffix, but /opt/local/lib/mysql5/bin has “normal” named binaries, so you probably want that in your PATH too. The apachectl in /usr/bin will spin up the mac os x version of apache (that we’re avoiding), and that lives in /opt/local/apache2/bin. So in your .bashrc (or .profile or whatever):

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/mysql5/bin:/opt/local/apache2/bin:$PATH

5. Install PHP5

sudo port install php5 +pear +apache2 +fastcgi +mysql5

Note that php5 has a lot of variants. If you think you want other goodness, run port variants php5 and cook up your own set of options.

Again, as the macports instructions state,

copy /opt/local/etc/php5/php.ini-development (if this is a development server) or /opt/local/etc/php5/php.ini-production (if this is a production server) to /opt/local/etc/php5/php.ini and then make changes.

6. Install the PHP-MySQL driver:

sudo port install php5-mysql +mysql5

7. Configure apache2

The mod_php.conf from the php5 package is put into a directory that the apache2 configuration doesn’t read by default — so you need to add this line to the end of /opt/local/apache2/conf/httpd.conf:

Include conf/extras-conf/*

Hopefully this will be considered a packaging bug, and will be fixed at some point.

8. Run apache2

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

Note that the logs, by default, are in /opt/local/apache2/logs.

If you change the PHP or Apache configuration files, run

sudo /opt/local/apache2/bin/apachectl restart

and watch the logs for errors.

Using Mac OS X 10.5′s keychain for ssh

The version of ssh that comes with Mac OS X 10.5.6 has a -K option that stores your passphrases in your system’s keychain.

Run this:

ssh-add -K [path to private keyfile]

Provide your passphrase once when asked, and keychain will provide the passphrase for you automatically. You should probably enable “Require password to wake this computer from sleep or screen saver” in the Security pane of the System Preferences if you decide to do this.

If you see

$ ssh-add -K
ssh-add: illegal option -- K

it’s because you’re using the macports (or fink) version of ssh. (run ‘which ssh’ to find out). With macports, uninstall the “openssh” package:

sudo port uninstall openssh

The ‘-K’ option was discovered courtesy of http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html.

http://kimmo.suominen.com/docs/ssh/ has some excellent ssh documentation.

Viscosity and Search Domains

I’ve really enjoyed Viscosity as my openvpn client for Mac OS X (instead of Tunnelblick). It’s stable, bounces back after system sleep, and is well supported.

After upgrading from 1.0.3 to 1.0.4, I found that my search domain configuration from the Network Settings control panel wasn’t being respected anymore while the VPN was up. I got the following reply (in 30 minutes, no less):

The 1.0.3 behavior was actually a bug (your system should use any search domains associated with the VPN connection for security reasons, rather than local search domains).

You can specify search domains to use while connected instead like so:

1. Edit your connection in Viscosity
2. Click on the Advanced tab
3. Add the command “dhcp-option DOMAIN mydomain.com” (no quotes) where mydomain.com is your search domain
4. Repeat step 3 for each search domain you have
5. Click Save and try connecting

These instructions worked perfectly. Thanks!

TaskPaper is All Sorts of Awesomeness.

I finally got around to trying out TaskPaper (one of the apps I got from MacHeist a while ago), and it’s a brilliant and simple todo app.

You enter something like this:

Inbox:
- Put camera in car
- Put pizza stone in car
Groceries:
- Milk
- Eggs
- Pizza toppings
Yard work:
- Rake leaves
- Put away hose @done
- Clean up garden @done

And you get a GUI treatment that looks like this:

It’s one of my must-have applications now.