2

I am new to Mac OS X El Capitan 10.11.4. I tried installing MySQL 5.7.4 on MAC OS X from .dmg file that contains .pkg file. In the first time installation it prompted a root password (I am not sure if it prompted or I missed) but I missed noticing it.

I again run the MySQL installation but it does not prompted the root user password this time during installation. I tried setting root user password from previous Stack Overflow post but nothing seems to work. Can you explain me process to reset MySQL root user password or to reinstall MySQL so that it prompt the root user password?

halfer
  • 19,824
  • 17
  • 99
  • 186
Shashank
  • 93
  • 1
  • 6
  • Pro tip: readers are often wary if they see "please provide step by step instructions for X", as it sounds like "I have not researched this at all and I am not willing to use a search engine". Now that may not be true, but it is good to reassure your readership that you have indeed made a prior effort. – halfer Aug 09 '16 at 17:34
  • I believe with MySQL you can stop the service, restart it with a "no authentication" mode, connect as root, create a new root user, and then restart normally. Would you look into that? – halfer Aug 09 '16 at 17:35
  • Possible duplicate of [Setting the MySQL root user password on OS X](http://stackoverflow.com/questions/6474775/setting-the-mysql-root-user-password-on-os-x) – halfer Aug 10 '16 at 23:02

2 Answers2

1

I got the solution; here is step-by-step process to reset root password in MySQL:

  1. Stop the mysqld server. This can be done by from 'System Preferences' > MySQL > 'Stop MySQL Server'

  2. Start the server in safe mode with privilege bypass

    From a terminal:

    sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
    
  3. In a new terminal window type:

    sudo /usr/local/mysql/bin/mysql -u root
    
    UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass')
    WHERE User = 'root' AND Host = 'localhost';
    FLUSH PRIVILEGES;
    
    \q
    
  4. Stop the mysqld server again and restart it in normal mode.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shashank
  • 93
  • 1
  • 6
0

What worked for me was, to uninstall the old 5.7 version (from the pkg installer) that didn't start and/or had issues showing the root password, and install the same version with brew.

1) Remove the remnants of the old installation.

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*

Use sudo at your own discretion, never copy paste commands from random people

2) Then proceed to install with brew.

$ brew update

$ brew info mysql@5.7
Expected output: mysql@5.7: stable 5.7.XX (bottled) [keg-only]

$ brew install mysql@5.7

$ echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
Because this is keg only, we need to manually put mysql in our PATH

$ mysql.server start
$ mysql.server stop
Use these commands to start/stop mysql

$ mysql_secure_installation

That was what I had to do to make it work.

opcode
  • 419
  • 5
  • 11