hgiesel hgiesel - 2 years ago 83
MySQL Question

Can't connect to mysql on OS X

I have installed

with Homebrew and I just can't access it.

When I run
mysql -uroot
, it says, I can't access. So I though maybe there was a password set. So I deleted
and ran
mysqld --initialize
. This output, besides other things:

A temporary password is generated for root@localhost: randomPassword

So I tried
mysql -uroot -p'randomPassword'. But this still doesn't work. What is my password? I may have installed
mysql` with Homebrew before that, but I can't imagine that the old password is still saved somewhere.

Answer Source

I don't have experience of MacOS installs. In my experience of Linux installs, it prompts for the user to enter a root password on install.

There are however a wealth of instructions around on how to reset the root password if not known. I have used the --skip-grant-tables method many times.

  • Stop the MySQL server
  • Restart it with --skip-grant-tables
  • Open up the mysql command line client
  • mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; for MySQL 5.7.6 and later, or
  • mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); for MySQL 5.7.5 and earlier

Source: MySQL Manual

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download