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]( “living-e AG: MAMP – Mac – Apache – MySQL – PHP”) on my system to develop web projects locally. I use MAMP because it has more up to date versions of [Apache]( “Welcome! – The Apache Software Foundation”), [PHP]( “PHP: Hypertext Preprocessor”) and [MySQL]( “MySQL AB :: The world’s most popular open source database”) 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]( “TextMate — The Missing Editor for Mac OS X”) 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 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.


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:
![How it should look in the TextMate SQL server prefernces](

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]


Adam Merrifield


11 thoughts on “Configuring TextMate SQL to play with MAMP

  1. 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?

  2. @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

  3. It just returns my name. It looks like this
    desktop:~ davidnestelle$ whoami

    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.

  4. David, if you choose to follow the link to 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

  5. 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?

  6. @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.

  7. 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?

    1. 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.

Leave a Reply