Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql on osx: access denied and can't connect to socket

Tags:

mysql

macos

I can't seem to figure out what I have to do in order to install/setup mysql correctly on my new mac.

1.) I installend mysql via homebrew

2.) I'm able to run mysql.server start

enter image description here

3.) If I try to run mysql -u root -p I get this

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

I googled and looked through all kind of sources, but can't seem to figure out what to do.


Update:

enter image description here

Update 2:

enter image description here

like image 992
matt Avatar asked Aug 06 '15 10:08

matt


People also ask

Could not connect to MySQL access denied for user?

You will get this error when the user user_name does not have the right to access your MySQL database. To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password';

Where is MySQL installed on Mac?

By default, the MySQL directories are installed under /usr/local/ . Even better, add /usr/local/mysql/bin to your PATH environment variable. You can do this by modifying the appropriate startup file for your shell. For more information, see Invoking MySQL Programs.


2 Answers

Let's stop mysqld:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Clean re-installation procedure:

brew remove mysql
brew cleanup
brew doctor

Backup your database before do next step. Then clean data directory up (to avoid manual run extra step mysql_install_db later):

sudo rm -rf /usr/local/var/mysql

The latest step is to install it again from scratch:

brew update
brew install mysql

Then run mysqld and try to login to CLI:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
mysql -u root
like image 96
Anatoly Avatar answered Sep 19 '22 12:09

Anatoly


On the 3rd step run it without -p option, which stands for password requirement: Run the command like this mysql -u root. If you need to set a password there is another post about it here.

like image 43
cmertayak Avatar answered Sep 18 '22 12:09

cmertayak