I’m having a hard time getting MySQL to work on my Mac. I used Homebrew to install it and tried to set up the root password. But now I can’t log in to the MySQL shell. Here’s what I’ve tried:
brew install mysql
mysql -uroot
# Error: Access denied for user 'root'@'localhost' (no password)
mysql -uroot -p
# Error: Access denied for user 'root'@'localhost' (with password)
sudo mysql -uroot -p
# Error: Access denied for user 'root'@'localhost' (with password)
mysql_secure_installation
# Error: Access denied for user 'root'@'localhost' (with password)
I’ve tried with and without a password, and even used sudo, but nothing works. The errors keep saying access is denied. What am I doing wrong? How can I fix this and get MySQL working on my Mac?
try uninstalling mysql completely and reinstalling from scratch. sometimes weird permission issues happen during install. also check ur system logs for any errors. i had to add mysql to my path variable before it worked right. good luck!
Have you considered using a GUI tool like MySQL Workbench or Sequel Pro to connect? Sometimes these can help diagnose connection issues more easily than the command line. Also, double-check your MySQL configuration file (/etc/my.cnf or /usr/local/etc/my.cnf) to ensure there are no conflicting settings. If all else fails, you might want to try purging MySQL completely (including config files) and doing a fresh install. Just remember to backup any important databases first. Alternatively, you could explore using Docker to run MySQL in a container, which can help avoid system-level conflicts.
I ran into a similar issue when setting up MySQL on my Mac recently and found that starting MySQL in safe mode can bypass the password authentication that often causes access issues. First, stop the MySQL service with the brew services stop mysql command. Then, start MySQL in safe mode by running mysqld_safe --skip-grant-tables & so that you can connect without a password using mysql -u root. Once connected, reset the root password using the ALTER USER command with your new password and remember to run FLUSH PRIVILEGES. Finally, exit the session, stop the safe mode process, and restart MySQL normally using brew services start mysql. If the problem still persists, you might want to check your my.cnf file for any conflicting settings.
Hope this helps.