Couple different things could be going on, I’ll start with the easy one.
First, localhost could be failing to resolve for whatever reason. Try pointing to the actual IP address first and see if that does anything. If it does, you should be set.
If you’re still not getting it to work (and you can run SQL queries manually, either through the command line or something like MySQL Workbench), try running SHOW GLOBAL VARIABLES LIKE 'PORT'; and make sure it returns 3306.