How to use a my.cnf configuration file with MAMP/MySQL

I don’t know why, but I was unable to get MySQL under MAMP 3.5 to read a my.cnf configuration file. I put that file in all of the usual places, but it wasn’t read. Then I tried to get it to read my configuration file by modifying this MAMP/MySQL startup script:

/Applications/MAMP/bin/startMysql.sh

but all I got then was an error message that these two options don’t work:

--defaults-file=FILE
--defaults-extra-file=FILE

I got those errors even though those options are shown in the mysqld_safe help output:

$ mysqld_safe --help
Usage: /Applications/MAMP/Library/bin/mysqld_safe [OPTIONS]
  --no-defaults              Don't read the system defaults file
  --defaults-file=FILE       Use the specified defaults file
  --defaults-extra-file=FILE Also use defaults from the specified file
  (more output here ...)

So what I did to solve this problem was to skip using a MySQL configuration file, and just put all of the options I wanted inside the MAMP MySQL startup script (/Applications/MAMP/bin/startMysql.sh).

The MAMP MySQL startup script

Here are the contents of the MAMP/MySQL startup script I created. I can confirm that this approach works with MAMP 3.5 on Mac OS X 10.10.5 (Yosemite):

/Applications/MAMP/Library/bin/mysqld_safe \
    --port=8889 \
    --socket=/Applications/MAMP/tmp/mysql/mysql.sock \
    --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid \
    --slow_query_log_file=/Applications/MAMP/logs/mysql_slow_queries.log \
    --slow_query_log=1 \
    --long_query_time=2 \
    --wait_timeout=28800 \
    --interactive_timeout=28800 \
    --log-error=/Applications/MAMP/logs/mysql_error_log &

# did not need this option
#--log_queries_not_using_indexes=1 \

So, while I can’t tell you how to get MAMP/MySQL to read a my.cnf configuration file, I can confirm that if you modify the MAMP/MySQL startup script as shown, this approach works.