I finally figured it out. Thanks to Max and Yogendra for posting.
The problem turned out to have been my XAMPP configuration. To fix it, I did as follows:
- sudo vi /Applications/XAMPP/etc/my.cnf
⁃ scroll down to `skip-networking`
⁃ comment it out by changing it to `#skip-networking`
⁃ save the changes.
⁃ restart mysql from XAMPP Console
Then I run my code and everything is fine!