Homebrew MySQL 8.0.18 on macOS 10.15 Catalina won't run as service

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-13 06:39:47

问题


Another macOS upgrade + another MySQL upgrade = another set of problems.

I can't seem to get MySQL 8.0.18 to run as a homebrew service on macOS 10.15 Catalina. Please show me the error of my ways.

Here's what I did:

  1. brew install mysql
  2. brew pin mysql
  3. touch /tmp/mysql.sock
  4. mysql.server start
  5. unset TMPDIR
  6. mysql_secure_installation
  7. mysql.server stop
  8. sudo brew services start mysql

Here's what I expected:

MySQL to run merrily along as a homebrew service as user root.

Here's what happened:

MySQL falls right over and dies, leaving a cryptic last statement in /usr/local/var/mysql/[host.domain.com].err:

"[ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!"

Additional information:

MySQL runs fine through subsequent reboots so long as I launch it manually:

sudo reboot now
ssh [servername.domain.com]
touch /tmp/mysql.sock
mysql.server start

Here's the /usr/local/var/mysql/[servername.domain.com].err file contents:

2019-10-20T18:02:14.6NZ mysqld_safe Logging to '/usr/local/var/mysql/moriarty.farces.com.err'.
2019-10-20T18:02:14.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2019-10-20T18:02:14.670494Z 0 [System] [MY-010116] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld (mysqld 8.0.18) starting as process 557
2019-10-20T18:02:14.685511Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-10-20T18:02:15.617696Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2019-10-20T18:02:15.626461Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2019-10-20T18:02:15.795626Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-10-20T18:02:15.833541Z 0 [System] [MY-010931] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: ready for connections. Version: '8.0.18'  socket: '/tmp/mysql.sock'  port: 3306  Homebrew.
2019-10-20T18:02:15.993739Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '127.0.0.1' port: 33060

After a reboot, when I try to run MySQL as a Homebrew service:

sudo reboot now
ssh [servername.domain.com]
sudo brew services start mysql

MySQL fails with the following error recorded in the /usr/local/var/mysql/[servername.domain.com].err file:

2019-10-20T18:44:13.780394Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-10-20T18:44:13.780503Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-10-20T18:44:13.780727Z 0 [System] [MY-010910] [Server] /usr/local/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18)  Homebrew.
2019-10-20T18:44:13.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/moriarty.farces.com.pid ended

回答1:


Oh geez, he says, shaking his head...

This was a case of RTFM, and I didn't. Here's the applicable page from the MySQL 8.0 Reference manual. And here's the magic juju:

Add user=root to the [mysqld] section of the /usr/local/etc/my.cnf file, like so:

# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
user=root



回答2:


Never use sudo with command brew. It will ruin the ownership of related files. Running brew as root is not supported.

Quote from Homebrew doc

tl;dr Sudo is dangerous, and you installed TextMate.app without sudo anyway.

Homebrew refuses to work using sudo.

Warnings from the source code of brew

check-run-command-as-root() {
  ...
  odie <<EOS
Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
EOS
}

Solutions

  1. Disable the service and remove the launchdaemon.

    # stop and unload the launchdaemon
    sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
    # remove the lauchdaemon file
    sudo rm -f /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
    sudo rm -f /tmp/mysql.sock /tmp/mysqlx.sock
    
  2. Fix ownership of files under /usr/local/

    sudo chown -R "$(whoami):admin" /usr/local/*
    # it will take some time
    
  3. Re-enable the MySQL service.

    # DO NOT USE "sudo brew"
    brew services start mysql
    
  4. At last, read the following words aloud: I'll never use sudo with brew again.




回答3:


MySQL refuses to start on Catalina because elevated privileges are required to run it.

You need to locate your MySQL bin directory first:

    which mysqld

The result you get should be similar to /usr/local/mysql/bin/mysql.

The support-files directory contains the required scripts needed to start-up MySQL, and is located in the same directory where the bin directory is located. In the above example, the support files directory will be /usr/local/mysql/support-files/.

Start the MySQL service with administrative privileges as follows:

    sudo /usr/local/mysql/support-files/mysql.server start

N.B: In case the output from the first command you run is different from the one above, adjust the support-files directory accordingly as explained above.




回答4:


I just encountered the same issue after upgrading to Catalina. If I started MySQL server from system preferences it would just start and stop itself. The solution for me was:

sudo /usr/local/mysql-8.0.17-macos10.14-x86_64/support-files/mysql.server start

instead of: /usr/local/mysql/support-files/mysql.server start

I've encountered a lot of problems with Catalina. Now I can't start/stop mysql server from system preferences, only from terminal.

It's my first post so I hope this helps, I only registered to answer you since you're the only one I found with the same question.




回答5:


I solved like this:

Remove MySQL completely Watching: https://gist.github.com/vitorbritto/0555879fe4414d18569d

Install MySQL with Download do MySQL community server

https://dev.mysql.com/downloads/mysql/

And Done! Successfully!



来源:https://stackoverflow.com/questions/58466272/homebrew-mysql-8-0-18-on-macos-10-15-catalina-wont-run-as-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!