The Aelfinn
The Aelfinn

Reputation: 16888

MacOS Mojave - brew install [email protected] - Access denied for user 'root'@'localhost'

When installing mysql via homebrew (i.e. brew install [email protected]) on MacOS Mojave, a seemingly succesful installation prints the following instructions:

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 -uroot

When mysql -uroot, or mysql_secure_installation is run, I get the following error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

How can I login to mysql to change the password for root?

Upvotes: 4

Views: 5722

Answers (3)

hailong
hailong

Reputation: 1515

I think all people running the mysql_secure_installation command after installation would get into this trouble.

We need to append the username and password parameters to get thought this:

mysql_secure_installation -u root --password=""

Upvotes: 0

m0wry
m0wry

Reputation: 1

After a new brew mysql install:

1) Make sure that mysql is running: brew services start mysql

2) Change mysql password: mysqladmin -uroot --password="" password 'NEWPASSWORD'

3) Secure mysql: mysql_secure_installation (using new password)

Upvotes: 0

The Aelfinn
The Aelfinn

Reputation: 16888

It seems that using an "empty string" password via the --password flag solves this problem:

mysql -uroot --password=""

Alternatively, you can manually start mysqld with --skip-grant-tables:

$ mysql.server --skip-grant-tables
$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

$ 

And finally change the password with:

mysqladmin -uroot --password="" password NEW_PASSWORD

Upvotes: 4

Related Questions