Reputation: 3320
I'm trying to reinstall mysql on my MAC OS X Yosemite. for this I followed the instruction as mentioned below
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/MySQL*
vim /etc/hostconfig and removed the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/MySQL*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
I also tried
brew uninstall mysql
after this I installed mysql using homebrew using command brew install mysql
.
After installation when I tried to run mysql -u root
It throws the following error
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
I didn't set password for mysql.I don't know what's going wrong.Any suggestion will be appreciated. Thank you
Upvotes: 27
Views: 53807
Reputation: 1
Go back to your settings page, select MySql option, stop and start MySql server. This might resolve your problem
Upvotes: 0
Reputation: 711
I also tried everything mentioned across the web, in the end it was my password which had special characters which the bash script was not processing correctly or something. All in all I just uninstalled MySQL and reinstalled with a simple password containing only numbers and alphabets and it worked like a charm.
TLDR - Make sure the password does not have special characters;
Upvotes: 0
Reputation: 9
I spent 5 hours on this error today, tried every solution that exists out there, and even re-installed MySQL several times but what worked for me:
while installing in the configuration settings instead of "Use Strong Password Encryption"
I selected "Use Legacy Password Encryption"
and everything worked fine.
Upvotes: 1
Reputation: 1187
mysql -u root -p
and then type your password which you created during installation to enter to mysql.
Upvotes: 0
Reputation: 1
If none of the above methods work, try the following method, which is applicable for macOS 13, MySQL 8, and installation via Homebrew.
1: unistall mysql: brew uninstall mysql
2 run cmd : ps -ax | grep mysql | grep -v grep
It will return a result:
3964 ?? 0:00.03 /bin/sh /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
4065 ?? 0:02.26 /opt/homebrew/opt/mysql/bin/mysqld --basedir=/opt/homebrew/opt/mysql --datadir=/opt/homebrew/var/mysql --
Remember the path /opt/homebrew/opt/mysql/
3 : Kill all PIDs that you receive , Example: sudo kill 3964
4 : Delete the mysql directory in the path obtained above /opt/homebrew/opt/.
5 : Finally, reinstall MySQL.
Upvotes: 0
Reputation: 13
Update for anyone still not finding a resolution with a new M1 Mac. This completely clears your database FYI!!
First run brew services stop mysql
I found it easier to just open finder and use the got to folder and open /opt/homebrew, under the var folder I deleted the MySQL folder and under locks I deleted the MySQL lock files.
brew install MySQL and followed the install again.
Upvotes: 0
Reputation: 3905
In my case with a Mac M1 and Mysql 8.0.29-arm64 this answer worked for me:
https://www.codegrepper.com/code-examples/sql/how+to+reset+root+password+in+mysql+m1+mac;
Run the server in safe mode with privilege bypass:
> sudo mysqld_safe --skip-grant-tables
In a new Terminal window
> mysql -u root
UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;
Then
> mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
Upvotes: 4
Reputation: 7656
I installed mysql
with homebrew
and got the same problem as you because mysql
has had an existing database with an existing password there. See this article for more details.
$ brew services stop mysql
$ sudo pkill mysqld
$ sudo rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot
Upvotes: 130
Reputation: 854
Uninstalling mysql completely and installing with an installer solved the problem for me.
Solution:
Download and Install mysql without brew. Specify your desire password here or based on the version the installer might mention you a password
set the path for for mysql
export PATH=$PATH:/usr/local/mysql/bin
Check whether its installed properly mysql --version
mysql -uroot p
to login
change the password if required mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root')
Upvotes: 1
Reputation: 1
You forgot to reset your temporary password. Re-install mysql, use the temporary password to connect to mysql and run:
mysql> SET PASSWORD = PASSWORD('your_new_password');
Upvotes: 0
Reputation: 371
I tried all the commands mentioned in the stackoverflow, but nothing worked. Finally, I deleted every mysql folder in mac and reinstalled mysql. Finally the command
mysql -u root
worked for me. Then atlast, I set password for the mysql root by editing the configuration file.
Upvotes: 0
Reputation: 51
I have resolved this issue for myself.
Please check my github with this link: https://github.com/LeVanTuan/access_sql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO)
Fix bug access denied on macos 10.12 (Sierra)
install mysql (https://dev.mysql.com/downloads/mysql/) if already installed, skip this step
Update password of 'root' to access.
Open Terminal (Launchpad -> Other -> Terminal or (Command + space) -> Type 'terminal' )
Then type follow below:
export PATH=$PATH:/usr/local/mysql/bin/
sudo mysqld_safe --skip-grant-tables
then, restart Terminal (quit then open again)
then, keep type:
export PATH=$PATH:/usr/local/mysql/bin/
mysql -u root mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
\q
sudo /usr/local/mysql/support-files/mysql.server start
extra: start mysql: sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables stop mysql: sudo /usr/local/mysql/support-files/mysql.server stop
I hope it will help you
Upvotes: 4
Reputation: 4821
Now sql generates an aliatory password that appears in the last screen.
sudo mysql -u root -h 127.0.0.1 -p
Enter password: (aliatory password)
we can change it
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';
Upvotes: 10