So, in case someone has the same situation and configuration as I had and is also about to go mad - this worked for me.
After a long story I had a brew-installed MariaDB which kept automatically restarting when I killed its process (this was brew's doing), which had a root password, which I did not know.
$ brew services list
This shows something like:
mariadb started jdoe /path/to/homebrew.mxcl.mariadb.plist
Stop the MySQL server with:
$ brew services stop mariadb
Then start it again without the root user (and not using brew):
$ mariadbd --skip-grant-tables &
Here, mysql_secure_installation
did not work for me because of the --skip-grant-tables
, and it would not work without the --skip-grant-tables
because it needed the password (which I did not have).
Trying $(brew --prefix mysql)/bin/mysqladmin -u root password hunter2
only returned strange errors and did nothing; $(brew --prefix mariadb)/bin/mysqladmin -u root password hunter2
also didn't work, gave different errors, and suggestions that did not work for me.
But you can log into mysql now without credentials: $ mysql
Here, the old method of updating the user table for root doesn't work because "Column 'Password' is not updatable".
The new method uses alter user
BUT only works after you have done flush privileges;
so do that first.
Then:
MariaDB [(none)]> alter user 'root'@'localhost' identified by 'hunter2';
(MariaDB [(none)]>
is the MySQL prompt here)
Then do flush privileges;
again.
Exit the MySQL client.
Now as far as brew is concerned, MariaDB is still not running, and so use $ ps aux | grep -i mariadb
to find the pid and $ kill -9 <pid>
it.
Then use $ brew services start mariadb
to start it again.