ERROR! MySQL server PID file could not be found!

I have reinstalled macOS Sierra on my machine. After installing Oracle MySQL Community Server 5.7.15 (mysql-5.7.15-osx10.11) I tried to stop the MySQL server from the console. I got back the following error "ERROR! MySQL server PID file could not be found!".

I have done some research on my own but it did not manage to find a solution on my problem.

Any suggestions?


Solution 1:

Starting and stopping the MySQL server via Preferences Pane/launchd and on the other hand via sudo /usr/local/mysql/support-files/mysql.server start/stop are not really compatible.

After choosing "Launchd Support" in the MySQL installer the launch daemon com.oracle.oss.mysql.mysqld will be created and the MySQL preferences pane uses the launchd mechanism to start and stop mysql. If you enable "Automatically Start MySQL Server on startup", mysqld is enabled automatically after starting your Mac.

The pid file's name created by the launch daemon is not compatible with the one created and expected by the mysql-server script.

The launch daemon's pid file name created while running is mysql.local.pid, the script expects a name based on your Mac's hostname, .local or computer name though.

So either use the MySQL pref pane/launchctl or the script to start and stop mysqld.


To some extent you can make both methods compatible by modifying the file com.oracle.oss.mysql.mysqld though:

After stopping mysql replace the array

<array>
    <string>/usr/local/mysql/bin/mysqld</string>
    <string>--user=_mysql</string>
    <string>--basedir=/usr/local/mysql</string>
    <string>--datadir=/usr/local/mysql/data</string>
    <string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
    <string>--log-error=/usr/local/mysql/data/mysql.local.err</string>
    <string>--pid-file=/usr/local/mysql/data/mysql.local.pid</string>
</array>

by

<array>
    <string>/usr/local/mysql/bin/mysqld</string>
    <string>--user=_mysql</string>
    <string>--basedir=/usr/local/mysql</string>
    <string>--datadir=/usr/local/mysql/data</string>
    <string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
    <string>--log-error=/usr/local/mysql/data/$name.err</string>
    <string>--pid-file=/usr/local/mysql/data/$name.pid</string>
</array>

with $name: either HostName (e.g. host.example.com), LocalHostName (e.g. host.local) or ComputerName (e.g. host). Probably the best is to use a hostname. You may get a hostname with hostname with scutil --get HostName or set it with sudo scutil --set HostName your_hostname.

You can also get the actually used mysql-server script pid's name - after stopping the launch daemon and starting mysqld with mysql-server start- by checking mysql's data directory with sudo ls /usr/local/mysql/data. Use the name found there to adjust the plist's pid name.

You may have to convert the launch daemon file to xml to edit it. The app TextWrangler opens it as xml file immediately.

Reload the plist with launchctl afterwards.


Now should be able to start and stop with the MySQL pref pane and the mysql.server script.

If you have enabled "Automatically Start MySQL Server on Startup", you can't stop the server – even after modifying the plist – with the script because launchd overrides any stop command after a few seconds and launches mysqld again.