0

I'm running macOS Mojave, just installed MySQL using the official installer. I can start/stop the server without problem from the Preference pane. But from the command line I always get Permission denied trouble:

$ mysql.server start
Starting MySQL
./usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 199: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysqld.local.pid).

I also tried with the mysqld and mysqld_safe commands with the same results.

The owner of the data directory is the _mysql user:

$ ls -l mysql/
drwxr-x---  42 _mysql  _mysql    1344 Nov  5 21:14 data

I would do su _mysql 'mysql.server start' for example, but I don't know the password of _mysql if it has any, I think it's not a login account.

So how can I start the server from the command line?

Update

As the official MySQL documentation explains here, to run the server as normal user you have to own the data directory recursively works:

$ chown bob -R /usr/local/mysql/data

I can start/stop the server from the command line, using any of the commands above, and connect to the server as well.

Problem is, now it doesn't work the Preference pane! Now the question is: Is there any way of getting back the Pref pane working? Most importantly, why did that happen?

Bobby Wan-Kenobi
  • 885
  • 9
  • 18
  • Don't change the owner of the mysql files to your user account. The configured mysql user (I guess it's the `_mysql` user) is the one who should run the mysql server, not your user account. – Progman Nov 05 '18 at 21:22
  • Possible duplicate of [start MySQL server from command line on Mac OS Lion](https://stackoverflow.com/questions/7927854/start-mysql-server-from-command-line-on-mac-os-lion) – Progman Nov 05 '18 at 21:28
  • @Progman, in that post they reference the official MySQL docs, and there they changed ownership of the data dir. Check it out: https://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html – Bobby Wan-Kenobi Nov 05 '18 at 21:47

2 Answers2

0

mysqld_safe is just a wrapper for the mysqld command that will start for you your mysql server with the correct user.

However, you should have to run it with sudo. If you find or manage to replace the password for your mysql user, you might be able to use directly the mysqld command.

So, a quick way to start your server is: sudo mysqld_safe.

Further details can be found on MySQL documentation: Starting the server

luzin
  • 9
  • 2
0

So no, the solution can't be found in start MySQL server from command line on Mac OS Lion, but it can be found here Basically in that post they explain that the pid file used by the launchd service (the pref pane uses that service) has a different name of the one that msqld uses:

  • The Preference pane call it mysqld.local.pid
  • msqld calls it the_name_of_your_localhost.local.pid

So if you start the server from the pane you mess the name of the pid file, and then the commands get confused because it looks for a pid file named differently. And the other way around.

We can find the same naming trouble with the error log file.

Also I found out that the names for the socket files are also different:

  • /tmp/mysql.sock for the commands
  • /tmp/mysqlx.sock for the service/pane

Maybe there's a way using configuration files to use unified names, but I couldn't make it work. At least now I understand the problem, although don't know how to fix it. In the meantime I'll have to to choose: either the command line or the preference pane, but not both. They are incompatible ;-)

Bobby Wan-Kenobi
  • 885
  • 9
  • 18