I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql
, but when I tried mysql -u root
I got the following error:
You'll need to start MySQL before you can use the mysql
command on your terminal. To do this, run brew services start mysql
. By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation
.
To connect run: mysql -uroot
. root
is the username name here.
In my case it was simply a matter of deleting a lock file.
sudo rm -f /tmp/mysql.sock.lock
I keep coming back to this post, I've encountered this error several times. It might have to do with importing all my databases after doing a fresh install.
I'm using homebrew. The only thing that used to fix it for me:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This morning, the issue returned after my machine decided to shut down overnight. The only thing that fixed it now was to upgrade mysql.
brew upgrade mysql
Ough, that took me a while to figure out. I saw it in a comment. After installing mysql using brew, and starting the service (perhaps using sudo brew services start mysql
) then run:
$ mysqld
And MySQL should be running for your thereafter.
only this has made the trick for me
brew services start --all
(after trying all answers)
/usr/local/var/mysql/
.