Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix brew-installed MariaDB that hangs on `mysql.server stop` and doesn’t stop?

This question is not a duplicate of mariadb server: I can't stop the server with `mysql.server stop`.

I don’t want to run MariaDB at boot so brew services isn’t an option.

MariaDB version is 10.4.11-MariaDB.

like image 325
sunknudsen Avatar asked Jan 27 '20 18:01

sunknudsen


2 Answers

Think I found the culprit.

Having a look at the source code of mysql.server (cat /usr/local/bin/mysql.server), I discovered that running mysql.server start runs mysqld_safe as me (whoami) which is what I expected.

Now, I also discovered that running mysql.server stop runs a su_kill function that runs su as mysql which fails because the mysql user doesn’t exist on macOS.

user='mysql'

su_kill() {
  if test "$USER" = "$user"; then
    kill $* >/dev/null 2>&1
  else
    su - $user -s /bin/sh -c "kill $*" >/dev/null 2>&1
  fi
}

Not sure if I am doing something wrong, but according to the documentation, running mysql.server start is the right way of starting MariaDB on brew installs.

Anyhow, to patch mysql.server stop, run:

cp /usr/local/bin/mysql.server /usr/local/bin/mysql.server.backup
sed -i "" "s/user='mysql'/user=\`whoami\`/g" /usr/local/bin/mysql.server
like image 190
sunknudsen Avatar answered Sep 28 '22 00:09

sunknudsen


Originally, whenever I tried mysql.server stop I would get the error:

ERROR! MySQL server PID file could not be found!

At some point, mysql.server stop would just hang.

Exploring @sunknudsen's answer, I cd'ed to the directory:

$ cd /usr/local/bin/

then opened the file:

mysql.server

The code user='mysql' only appears on one line, so I just commented out that line and replaced it with:

185 #user='mysql'
186 user=`whoami`

Now, this is what happens:

~$ mysql.server start
Starting MariaDB
.200804 15:43:28 mysqld_safe Logging to '/usr/local/var/mysql/My-MacBook-Pro-2.local.err'.
200804 15:43:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
 SUCCESS! 

~$ mysql.server stop
Shutting down MariaDB
. SUCCESS! 

~$ mysql.server stop
ERROR! MariaDB server PID file could not be found!

The correct start/stop status is also indicated in System Preferences/MySQL.

like image 28
7stud Avatar answered Sep 27 '22 23:09

7stud