17
votes

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

7
Did you tried mysql -u root -p?scherard
yes I tried it.but it ask for password and on pressing entering it raise above errorBibek Sharma

7 Answers

104
votes

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
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot
6
votes

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';
3
votes

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

0
votes

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.

0
votes

**on your mac terminal type mysql -u root -p

0
votes

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');
0
votes

Uninstalling mysql completely and installing with an installer solved the problem for me.

Solution:

  • Remove mysql complete from your computer

  • 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')