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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With