Mysql – Can’t open the thesql.plugin table error when installing MySQL on Mac OS Sierra

installationmac os xMySQLmysql-5.7upgrade

I am attempting to install MySQL on macOS Sierra 10.12.5. I had a previous (non-functioning) install of MySQL so I followed the steps here to install a clean copy with Homebrew.

I had to create a var/log/mysql/error.log as it wasn't created automatically, however now it is logging I get the following error when I do a mysql.server start:

2017-07-24T13:36:28.554840Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2017-07-24T13:36:28.563492Z 0 [ERROR] unknown variable 'key_buffer=16M'
2017-07-24T13:36:28.563534Z 0 [ERROR] Aborting

This is how I initialised MySQL:

mysqld -initialize --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql

When I start MySQL with homebrew I get no error:

CRMPiccos-MacBook:~ crmpicco$ brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

Version info:

CRMPiccos-MacBook:log crmpicco$ mysql --version
mysql  Ver 14.14 Distrib 5.7.19, for osx10.12 (x86_64) using  EditLine wrapper

Best Answer

In my case mysql failed after the update because the user running mysqld (The user mysql) being unable to open the mysql data directory with write permission. The files were instead owned by myself. I fixed this with:

sudo chown -R mysql /usr/local/mysql/*

The orignal cause (for me) was not the Sierra upgrade itelf, but the overall process of updating applications in response. Specifically other instructions online for updating PHP with brew after the Sierra update had included a chown:

sudo chown -R $(whoami):admin /usr/local # DO NOT DO THIS

This had unfortunately altered the file permissions within /usr/local/mysql within /usr/local, causing the error.