24

I have MacOS Sierra. I have installed MySQL Server which has been working, however, after a reboot of the Mac Book, I cannot start the MySQL Server.

enter image description here

I have tried changing the port from 3306 to 3307 in the my.cnf file.

Question

I would appreciate any help on how to start the MySQL Server, and also have it so it starts automatically on MacOS Boot up.

(I am new to Mac, so apologies if this is a basic question).

UPDATE

Looking for error logs, I can't find anything with todays (2/2/2017) timestamp.

enter image description here

Nothing in the data dir:

enter image description here

No files with "mysql" have been modified since I've tried to start the MySQL Server (2/2/2017 after 09:00).

enter image description here enter image description here

Richard
  • 8,193
  • 28
  • 107
  • 228
  • 2
    You should have an 'error' file - on mine its in /usr/local/var/mysql and will be something like .local.err. Have a look in there and see if theres anything obvious (should be near the end of the file). – FreudianSlip Feb 02 '17 at 06:59
  • And, if you used brew to install your mysql, use 'brew services start mysql' to get it to auto-start. – FreudianSlip Feb 02 '17 at 07:01
  • I can't find any error logs (look at update above). Am I looking in the wrong place? I just downloaded and ran the installer, so didn't use brew. – Richard Feb 02 '17 at 07:06
  • You're looking in the lib/plugin/debug dir from what I can see there - have a look at the root of where your databases are created (your datadir). – FreudianSlip Feb 02 '17 at 07:08
  • There's nothing there (see UPDATE above). – Richard Feb 02 '17 at 07:13
  • Then im suspecting your installation didnt work - you should have at least the mysql dir, maybe the performance_schema dir and probably (if you use innodb) some ibdata & ib_logfiles. Try doing a find for ibdata1 : sudo find / -name 'ibdata1' – FreudianSlip Feb 02 '17 at 07:16
  • 1
    I have been using it successfully that last few weeks, but did a computer reboot this morning, and now having this issue. Will do a search as you suggest. Appreciate the help. – Richard Feb 02 '17 at 07:20
  • The search returns (see above). – Richard Feb 02 '17 at 07:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134659/discussion-between-freudianslip-and-richard). – FreudianSlip Feb 02 '17 at 07:25
  • Tried to reboot my computer, but still the server is unresponsive. – Richard Feb 02 '17 at 08:33
  • Thanks, I tried updating my.cnf as you suggested, but still no joy. – Richard Feb 02 '17 at 09:26

11 Answers11

41

I suggest using Terminal commands.

Start MySQL

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

Stop MySQL

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

Restart MySQL

sudo /usr/local/mysql/support-files/mysql.server restart
Saad
  • 3,340
  • 2
  • 10
  • 32
Ares
  • 2,504
  • 19
  • 19
  • 1
    This helped me as I was able to see the permissions error causing the problem. – Jack BeNimble May 30 '20 at 21:53
  • 1
    Thanks a lot, MySQL server on my macOS High Sierra crashed when i removed a foreign key. killed all mysql processes and then used this command to start mysql again because it wont start from settings. – Faizan May 06 '21 at 22:57
  • Thanks for these commands, it really helped! – Alex Yao Jan 22 '22 at 15:37
10

In my case, I had inadvertently transferred ownership of entire /usr/local directory to myself, which resulted in snatching-away of write permission of /usr/local/mysql-5.7.20-macos10.12-x86_64/data directory from the daemon user called "_mysql".

Restoring the ownership fixed the issue.

y2k-shubham
  • 10,183
  • 11
  • 55
  • 131
9

After a discussion with Richard, the following solves the issue:

my.cnf:

[client]

port = 3306
socket = /tmp/mysql.sock


[mysqld]

port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql-5.7.17-macos10.12-x86_64/data
tmpdir = /tmp

Essentially, although we'd added the relevant stanza's to the my.cnf file, we'd still missed the section heading. Adding the [mysqld] section allowed mysql to start.

FreudianSlip
  • 2,870
  • 25
  • 24
8

After installing Mysql 8.0.12 on MacOS High Sierra, Mysql server would not start up. I tried several suggestions like removing mysql and reinstalling it, rebooting the computer and changing file permissions, all to no avail. I finally got it to work by removing /etc/my.cnf.

Sabine
  • 121
  • 4
  • 4
  • 2
    I just deleted the file and then started Mysql through the Pref Pane in the System settings and the 'lights' stayed green instead of turning red again right away after clicking the start button. I'm not sure but the my.cnf might have a been a remainder of an older mysql version. – Sabine Oct 22 '18 at 11:30
  • This was the issue for me. I think when deleting all of old mysql files on the system, I forgot to delete this one. – wtflux Feb 12 '20 at 13:10
  • this was the problem for me as well. – Russell Lego Oct 20 '20 at 18:21
  • *Utterly weird* as this seems to have been for me too, this seems to have worked. – Mike Robinson Nov 28 '22 at 03:26
8

In my case, ownership of the msyql directory had somehow changed to admin:admin. I use ares suggestion to run mysqld from the terminal:

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

Which showed a permissions error writing to a msyql file.

I fixed with this command:

sudo chown -R _mysql:wheel /usr/local/mysql/data

from this post:

What user should own /usr/local/mysql on Mac?

Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
7

In my case, First time, after installing Mysql, Mac needs a restart.

So restarting Mac, after installation, fixed the issue for me.

MacOS doesn't come with a my.cnf file. Default settings will suffice the needs for basic usage. Once we need to override them, it makes sense to have a custom configurations.

Sairam Krish
  • 10,158
  • 3
  • 55
  • 67
5

This solution works for me.

enter image description here

You have to open the activity monitor up and search for mysqld service. Once selected, just click the delete button located in the up left part and you will see the memory goes down. After that, you can verify your mysql server status from System Preferences and the service is up.

With this solution you don't have to restart your machine and get to work fast.

Osvaldo Cabrera
  • 327
  • 4
  • 4
3

My problem was that due to an incorrect restart of my machine, a database was corrupted. According to their docs doing a forced InnoDB Recovery did the trick:

/etc/my.cnf

innodb_force_recovery = 2
Gabriel Lupu
  • 1,599
  • 1
  • 12
  • 16
1

My problem was that I installed MySQL a while ago with Homebrew (forgot I did) and then went the more manual route, so I think the two installs were fighting each other. I wiped my Mac of both with the help of this walkthrough: https://gist.github.com/vitorbritto/0555879fe4414d18569d

Note: Where it says to use subl - that's Sublime, use whatever editor you like.

I was able to get things to work with a fresh install after that.

Akexis
  • 129
  • 9
  • 1
    Yes, similar. But I *still* ran into the problem that "the server would not stay started," which I was able to "solve" by deleting a `/etc/my.cnf` file that, for whatever reason, was never thereafter re-created by anyone. (See "Sabine"'s comment above.) – Mike Robinson Nov 28 '22 at 03:46
1

I had this same issue on Monterey. Make sure you're selecting the correct download according to your processor architecture. Processor architecture for MySQL Download

Kem Andrew
  • 26
  • 4
0

I ran into same problem with following .err log.

MacOS: Catalina 10.15.7.

MySQL version: 5.7.19.

2021-08-19T02:17:26.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2021-08-19T02:17:27.303813Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-19T02:17:27.318280Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-08-19T02:17:27.335112Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.19) starting as process 2828 ...
2021-08-19T02:17:27.421394Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2021-08-19T02:17:27.428986Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2021-08-19T02:17:27.429541Z 0 [ERROR] Aborting

2021-08-19T02:17:27.429688Z 0 [Note] Binlog end
2021-08-19T02:17:27.432786Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

And I found adding --user=root to Ares's answer will start mysql server successfully.

sudo /usr/local/mysql/support-files/mysql.server start --user=root

Ref.: MySQL Server Command User Options

George
  • 91
  • 6
  • same here - i can run this via command line, but i still can't start it via the system preferences app. what's happening? – nsdb Mar 20 '22 at 22:08