Truth in attempting to assist ... don't run Mac Server, but it's close to Linux.
Have you checked server logs ... apache error log, mysql, and/or php logs?
The error seems to indicate PHP is working, but moodle php code can't talk to the DB server. What's the difference in settings for phpmyadmin and what's in config.php of Moodle related to DB?
From command line of terminal (might have to add sudo to commands below), what does the following show?
which php (shows the php exec path ... or the one a php command would use)
php -v ... shows version of PHP
php -m ... shows PHP modules ... you should see mysql mysqli mysqlnd
If the server is running you should be able to connect to it via command line, shouldn't you?
Did the upgrade to the server actually install another copy of MySQL ... not the one you are trying to use via Brew?
What happens when one attempts to use mysql from command line?
mysql [enter]
Have more than one mysqld process running?
ps auxww|grep [m]ysqld
'spirit of sharing', Ken