Connecting to MySQL for MAMP Installations

By default, the MAMP installation may turn off TCP/IP networking and may use a custom local socket file location when launching MySQL. For example, the MAMP configuration file may have skip-networking set to on and may use the following for the local socket location:

/Applications/MAMP/tmp/mysql/mysql.sock

Many MySQL tools require either TCP/IP networking to be turned on, or require the mysql.sock file to be located in a particular location.

Since the default MAMP installation does not turn on TCP/IP networking, tools that use JDBC, i.e., the MySQL Connector/J JDBC driver, would not be able to connect without configuration changes.

To turn on the TCP/IP connection, the skip-networking parameter in the mysql configuration file should be commented out. Also, if you do not want to allow remote connections to your mysql database, i.e., you want the only connections to your database to come from the local machine, the bind-address parameter can be set to 127.0.0.1.

Making the above changes should allow tools like RazorSQL to connect to your MAMP MySQL database.

Below is information on the configuration changes needed so that tools that expect the mysql.sock file to be located in the /tmp folder work correctly.

One way to change the socket location is to edit the MAMP start and stop scripts so that the mysql.sock location is the default. This can be done by editing the following files:

/Applications/MAMP/bin/startMysql.sh
/Applications/MAMP/bin/stopMysql.sh

Replace

socket=/Applications/MAMP/tmp/mysql/mysql.sock

with

socket=/tmp/mysql.sock

A temporary solution is to open up a terminal window and execute the following:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

This will create a symbolic link to the MAMP socket file from the normal socket file location. This link will go away when MAMP is stopped or your machine is restarted.