0

I run brew install mysql or brew install mariadb then mysql_install_db and mysql_secure_installation but since I don't know the mysql password I just keep getting Access denied for user 'root'@'localhost' errors. It says it created root@localhost user with no password but I have to be the root system user. It also said it created another user without a password but I can't connect with that user either.

I've tried both of these solutions and nothing works:

Along with a couple other tutorials but it always comes back to needing to know the current password and I get stuck. Has anyone else had any luck installing mysql or mariadb on macos with brew?

Edit: I uninstalled and reinstalled and even after deleting /usr/local/var/mysql, when I run mysql_install_db it says mysql.user already exists so it can't install. How do I remove all databases when uninstalling?

Edit 2: So I think I finally managed to change the password but I keep getting this error message while trying to do mysql_secure_installation: Enter current password for root (enter for none): /usr/local/bin/mysql_secure_installation: line 249: .my.cnf.29733: Permission denied /usr/local/bin/mysql_secure_installation: line 250: .my.cnf.29733: Permission denied /usr/local/bin/mysql_secure_installation: line 251: .my.cnf.29733: Permission denied /usr/local/bin/mysql_secure_installation: line 253: .my.cnf.29733: Permission denied /usr/local/bin/mysql_secure_installation: line 218: .mysql.29733: Permission denied /usr/local/bin/mysql_secure_installation: line 220: .mysql.29733: No such file or directory

Dillan Wilding
  • 1,030
  • 2
  • 12
  • 28

3 Answers3

1

I finally got it to work and decided for posterity I should update my question. Uninstalling and reinstalling mysql or mariadb via brew doesn't remove data. So I found a list of possible mysql files and went through the list and removed mysql and mariadb files.

I followed this answer for the most part except I didn't do #4 or #5: brew install mysql on macOS

The result of the mysql_install_db was 2 new user accounts. Since I don't use root on my computer, I use the user account for my user which has no password so I do a mysql -u dillanjwilding and then do a mysql password reset for my user. Exit and mysql -u dillanjwilding -p type my password and works. I can even connect via Sequel Pro. So everything seems to be working as expected now, at least for now.

Dillan Wilding
  • 1,030
  • 2
  • 12
  • 28
0

Access the database using the mysql or the sudo mysql command.

Reference this answer to understand why a password is not needed.

As for resetting the MariaDB installation, run the following commands.

brew uninstall mariadb

rm -rf /opt/homebrew/var/mysql
rm -rf /opt/homebrew/etc/my.cnf
rm -rf /opt/homebrew/etc/my.cnf.d
rm -rf /opt/homebrew/etc/my.cnf.default

brew install mariadb
Hyunbin
  • 423
  • 4
  • 6
-1

As I understand it, the root account after install is accessed like this

mysql.server start
sudo mysql -u root

You then use the sudo password for your machine to execute this. Then the password for the mariadb is empty so it does not ask, or just push enter if it asks for the mariadb password.

You can then add new users for this admin account, and those can be accessed normally (without sudo)

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
nomail
  • 1