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:
Run: brew info mysql
And follow the instructions. From the description in the formula:
Set up databases to run AS YOUR USER ACCOUNT with:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysql_install_db:
mysql_install_db --help
and view the MySQL documentation:
* http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
* http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
Hope this helps.
Try this
rm -rf /usr/local/var/mysql && brew postinstall mysql@5.7 && brew services restart mysql@5.7
After trying many solutions, seems like the one that finally did the trick was to connect by IP. No longer file sockets getting deleted randomly.
Just update your MySQL client config (e.g. /usr/local/etc/my.cnf
) with:
[client]
port = 3306
host=127.0.0.1
protocol=tcp
Running sudo chown _mysql /usr/local/var/mysql/*
helped me finally after trying multitude of options from all these SO answers. The issue with permissions probably arose from improper shutdown of the machine.
A lot of other helpful responses here, but nothing fixed this for me. Ultimately nothing I found on this site or others would get any version of MySQL from Homebrew working for me.
It was super painless to just download the DMG from https://dev.mysql.com/downloads/file/?id=479114 (find the appropriate version you need) and let the wizard install it for me. The only other manual step was adding /usr/local/mysql/bin
to my PATH.
I'd recommend this option if brew is giving you trouble.
Update - if this still doesn't fix it, try completely purging mysql before installing via DMG. Follow these instructions: https://gist.github.com/vitorbritto/0555879fe4414d18569d
Solutions revolve around:
changing MySQL's permissions
sudo chown -R _mysql:mysql /usr/local/var/mysql
Starting a MySQL process
sudo mysql.server start
Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e
mysql -u root -p h127.0.0.1