Don’t get tripped up by MySQL/MariaDB skip-networking default in MacPorts

I recently decided to switch one of my MacBooks from MySQL installed with the binary package to MariaDB installed through MacPorts. I’ve used MacPorts for years and it has worked great for me, although I realize that isn’t the case for everyone.

After installing MariaDB, when I started Alfresco, it couldn’t talk to the database. I thought it might be a MariaDB problem, so I poked around a bit and then installed MySQL from MacPorts. Same problem.

I noticed that the problem was only with JDBC connections. Python didn’t have any trouble connecting nor did any of my non-JDBC database tools. A clue.

Then I noticed that “netstat -an|grep 3306” came back with nothing indicating that the database wasn’t listening on the port at all. I thought maybe it was a networking problem. Maybe permissions. Maybe a my.cnf issue. I tried tweaking all of that but wasn’t making any progress.

I decided there must be a .cnf file somewhere that was hosing me. It turns out that MacPorts installs a default .cnf file for both MySQL and MariaDB that has “skip-networking” turned on. That turns off all network-based connections to the server and that includes JDBC.

I have no idea why that is turned on by default but if you don’t know to look for it, you may chase your tail for a while. The fix is simply to edit the default .cnf file and comment out skip-networking. For MySQL, the file lives here:

/opt/local/etc/mysql55/macports-default.cnf

And for MariaDB the file lives here:

/opt/local/etc/mariadb/macports-default.cnf

6 comments

  1. Ruben Schade says:

    “I have no idea why [skip-networking] is turned on by default”

    I’d say its a prudent security measure, especially for a package manager like MacPorts where users are generally creating stacks for personal local development. You don’t want to be exposing network services you weren’t expecting.

    That said, if the default for MySQL/MariaDB is to enable it, it may be a cause of confusion as it was for you here. Any deviations from the default should probably be documented somewhere.

    Cheers

  2. El Jonhnny says:

    [quote]And for MariaDB the file lives here:

    /opt/local/etc/mariadb/macports-default.cnf[/quote]

    I didnt ever had find it 🙁 no in my maria db folder or programdata folder

  3. Clemens says:

    There is a very simple reason for this default, and it’s not security. MacPorts has a guideline of never auto-starting daemons after installation, so we assume people are aware of the possible security implications when they (actively) start the daemon.

    The real reason is that this allows multiple versions and forks of MySQL to run alongside each other – they use different sockets, but the same TCP port. Note that the mysql*-server ports are very explicit about this: A message during installation warns you about this change and explains where it can be configured. Type “port notes mysql56-server” to read it after installation.

  4. vitorg says:

    Don’t change /opt/local/etc/mariadb/macports-default.cnf contents, all your changes will be removed on update.

    Correct ways is to add this into /opt/local/etc/mariadb/my.cnf:
    [mysqld]
    skip-networking = 0 # Overriding faking MacPorts defaults.

Comments are closed.