Cannot locally connect to MySQL

37 views Asked by At

So I installed mysql using brew, and I run brew install mysql (and later brew reinstall mysql as well). I tried to access mysql as a root user, but it does not allow me to do so.

We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql
==> Summary
  /opt/homebrew/Cellar/mysql/8.3.0_1: 323 files, 312.8MB
==> Running `brew cleanup mysql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
(base) <mycomputer> ~ % mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1

There are 1 answers

0
det.antoine On

You may want to call brew services start mysql command first to allow the connection.