How to Connect MySQL in macOS via

MySQL Database

Usually any application connecting to MySQL in macOS (macport) is via localhost or, and there might be error if the application is connect via

This usually happened if MySQL service is installed via Macports, it’s due to Macports make it easier to run multiple MySQL version i.e MySQL 5.6, MySQL 5.7 or MariaDB, hence it only allow to connect via socket.

These are the errors you will see if you are connecting via localhost or

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘’ (61)

Here is how to enable and allow MySQL connection via in macOS.

  1. Edit the file /opt/local/etc/mysql56/macports-default.cnf (or the version you are using)
  2. Uncomment the item skip-networking
  3. Restart MySQL via command
    1. sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql56-server.plist
    2. sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql56-server.plist

Try connecting MySQL Server again with command

mysql -h -u root -p

You should be able to connect via!