How to set query_cache_type=2 on mac?
Could not find proper my.cnf, so had to find the preferred location where mysql is searching for my.cnf by using the command:

mysql --help | grep cnf


which displays

/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf


So I created a file  /etc/my.cnf with the required settings, restarted the server, and everything worked like a charm.