I'm using brew install mysql
/brew install mariadb
, and cannot find a way around the following error:
ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2)
Here are the key takeaways:
- I have nothing running on ports 80, 8080, 3306, etc.
brew services list
showsmysql
/mariadb
as stopped, regardless of how I start it up.- I've looked at permission settings using
sudo chown -R mysql:mysql /opt/homebrew/var/mysql
andsudo chown -R mysql:mysql /opt/homebrew/var/mysql
. - There are no set flags when running
ls -lO /opt/homebrew/var/mysql
orls -l0 /opt/homebrew/bin/mariadb
- My default
my.cnf
file (as per Homebrew's installation) is tiny. It only contains abind-address
and amysqlx-bind-address
– both127.0.0.1
. - I cannot find a
/tmp/mysql.sock
file anywhere, and know it's not enough to simply create one. - Installing MySQL through the DMG actually works, although I need to use MariaDB primarily and that is only available through
brew
.
I've looked at other questions here to try and find an answer. I've gone through solutions relating to macOS root passwords, access denied issues with brew installs, tried the solutions in an answer on ServerFault, and many of the other top answers on this issue over at ServerFault.
What else could I look into to fix this? Could there be a more complex permissions issue, and if so, how do I go about diagnosing it? I'll of course add further details here if requested, so please let me know what you'd want to see.
UPDATE 10-Apr
After looking at my .err
logs, it appears as though I have some data corruption in the ibdata1
table:
2024-04-10T22:19:41.436840Z 1 [ERROR] [MY-012224] [InnoDB] Tablespace flags are invalid in datafile: ./ibdata1, Space ID:0, Flags: 21. Please refer to http://dev.mysql.com/doc/refman/8.3/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2024-04-10T22:19:41.436882Z 1 [ERROR] [MY-012237] [InnoDB] Corrupted page [page id: space=0, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
2024-04-10T22:19:41.436891Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Data structure corruption.
2024-04-10T22:19:41.438452Z 1 [ERROR] [MY-011013] [Server] Failed to initialize DD Storage Engine.
2024-04-10T22:19:41.438575Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2024-04-10T22:19:41.438583Z 0 [ERROR] [MY-010119] [Server] Aborting
To try and get round this, I've looked to use innodb_force_recovery = 1
in my.cnf
, and went up to 6. mariadb-safe --skip-grant-tables
hasn't fixed anything either.
Running brew services start -v mariadb
gives me the following:
/bin/launchctl enable gui/501/homebrew.mxcl.mariadb
/bin/launchctl bootstrap gui/501 /Users/<user>/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/<user>/Library/LaunchAgents/homebrew.mxcl.mariadb.plist` exited with 5.
However, I don't have a storage issue, nor does my hard drive seem to have any issues.
UPDATE 11-Apr
I had already checked this, but wanted to recheck permissions and for flags on /opt/homebrew/var/mysql
and /opt/homebrew/bin/mariadb
as detailed in the takeaways list. Here's what I've done:
- Ran
dscl . -list /Groups
and confirmed there is the_mysql
group. - Ran
id mysql
and confirmed it's a member of the_mysql
group (uid=74(_mysql) gid=74(_mysql)
) - Ran
ls -lO /opt/homebrew/bin/mariadb
to check the permissions formysql:mysql
andusername:admin
(755lrwxr-xr-x
) - Ran
ls -lO /opt/homebrew/var/mysql
to check the permissions formysql:mysql
andusername:admin
(700drwx------
)
I've also reconfirmed solutions I'd already come across and discarded:
- Removing
mysqlx-bind-address = 127.0.0.1
frommy.cnf
(and the various other solutions) based on this question.
/opt/homebrew/var/log
when they could be in a few different places (per this Server Fault thread). For instance, a fresh Homebrew-based install ofmysql
on my own Mac just now created logfiles in the directory/opt/homebrew/var/mysql
. In my case there was a file in that directory titled with the hostname of my machine followed by.err
, containing logs for the MySQL service I started just beforehand. I would assume there's something similar on your side.127.0.0.1
instead oflocalhost
to ensure you're going over the TCP stack instead of the unix socket.