Configuring TextMate SQL to play with MAMP
I want to preface this by saying that I might be totally ass backwards in doing this but I had a need and I answered it. So before you try what I am about to tell you, be warned, if this totally obliterates your computer, project, or anything at all… it’s not my fault!
Ok, here is my needs, part 1; I run MAMP on my system to develop web projects locally. I use MAMP because it has more up to date versions of Apache, PHP and MySQL and I can update any of those on the fly at any time. It’s great that OS X has all of this pre installed (save for the MySQL), but it just isn’t very fast and I’ve always felt that by banging on the these system services I can potentially harm my system as a whole. With MAMP, I can bang on the innards of it’s services all I want and only worry about breaking that which resides in the MAMP folder.
My needs, part 2; I am a heavy, heavy TextMate user and as it happens, TextMate is a brilliant SQL editor which allows for complex queries to be written in a comfortable editor (as opposed to the very linear Terminal.app) and executed in a sexy little browser. The problem with is that TextMate presumes you will compile your MySQL server in the standard location and configuration (/usr/local/mysql/), where as MAMP puts it all in it’s own folder located in the Applications folder (/Applications/MAMP/tmp/mysql/).
What I have found is that TextMate want’s to access the socket (mysql.sock) in the /tmp/ folder (buried in the /private/ folder on the hard drive), but I know the MAMP socket is located at /Applications/MAMP/tmp/mysql/. So I thought I would try making an alias of this socket in the /tmp/ folder for TextMate to find. And it worked.
WARNING: IF THE TERMINAL SCARES YOU THEN LOOK NO FURTHER
First, open terminal, then type in the following line to create the link (this is based on the assumption that you already have a /tmp/ folder which you should):
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Next, you want to change the owner:
sudo chown _mysql /tmp/mysql.sock
And lastly the permissions:
sudo chmod 777 /tmp/mysql.sock
Now from the SQL bundle preferences in TextMate, add your server and database info (assuming you have already created a database). Remember that by default, MAMP MySQL administration is set to user: root, password: root (yikes, you might want to change that). It would look something like this:

That’s it! Now you can freely execute SQL queries from TextMate using your MAMP MySQL engine.
[tags]TextMate, MAMP, MySQL, SQL, PHP, Apache[/tags]

September 5th, 2008 at 4:18 pm
Just came up against this problem myself with my MAMP setup, great solution! Thanks
November 28th, 2008 at 12:19 pm
I am having trouble with this. When I enter the second command “sudo chown _mysql /tmp/mysql.sock”. I get the error message “chown: _mysql: Invalid argument”
Do you know why this is?
November 28th, 2008 at 12:36 pm
@David, that would lead me to believe that mysql isn’t present or enabled on your machine? Or you are not the admin… what do you get when you type whoami into the command line, i.e.: Mac-Pro:~ username$ whoami
November 28th, 2008 at 2:31 pm
It just returns my name. It looks like this desktop:~ davidnestelle$ whoami davidnestelle
I am a complete novice, in fact the reason I’m trying to do this is so I can learn SQL. So any help is greatly appreciated! Thanks.
November 28th, 2008 at 2:36 pm
@David, well it looks like you have the privileges you need. If your new though, you might want to start here first: http://danbenjamin.com/articles/2007/11/installing-mysql-on-mac-os-x and http://www.klauskomenda.com/archives/2008/10/07/installing-apache-mysql-and-php-on-leopard/
November 29th, 2008 at 9:55 pm
David, if you choose to follow the link to danbejjamin.com you will encounter a step that will set a export path to the mysql server you just configured. While the path will suffice for that specific server you will wan to change the path to the mysql server bundled with MAMP.
To run the MAMP mysql server change the path to: export PATH=”/Applications/MAMP/Library/bin:/usr/local/mysql/bin:$PATH”
/usr/localmysqlbin is just a default incase /Applications/MAMP/Library/bin is missing
now text mate will know how to find your MAMP mysql server and you can activate your query browser in text mate with control + shift + q
May 7th, 2009 at 9:33 pm
Hi. Interesting post you have. I was looking to something similar but with regards to the TM cmd+shift+R, when I want to run a PHP script with the TM internal browser. I was wondering if we could config TM to use the MAMP installed PHP instead of the MacOS PHP installation?
May 7th, 2009 at 9:47 pm
@SohDubom you probably could, but both Safari and FireFox will refresh as well if they are open, ultimately making the internal TM browser redundant. Since the TM browser is a bit underpowered I would go with the proper browsers.
September 4th, 2009 at 4:32 pm
worked like a charm. thanks a bunch.
April 16th, 2010 at 7:31 pm
Nice post but the image for the TextMate SQL bundle preferences is missing so we can’t see which SQL connection parameters to use! I’m using MAMP and phpMyAdmin works fine but TextMate won’t connect. I tried these values in the SQL bundle preferences and it just gives an error “Lost connection to MySQL server during query”.
Title: mydb Server: MySQL Username: root Hostname: localhost Port: 8889 Database: mydb
I tried ports 8888, 8889 as well as leaving it blank. “ps -awx” shows that “mysqld_safe” was started on port 8889.
Any ideas?
April 19th, 2010 at 11:52 am
My apologies, but some of these older posts have been moved from blog to blog to blog. I think this is more or less what the original image showed.