Notes: Reset Expired root Password for MySQL 5.7 on Mac OS X

I installed MySQL 5.7 from a .dmg package installer for Mac OS X. I followed the installer taking note of the temporary root password given. After the installation, I cannot login as root because the password expired. Here’s what I did.


I stopped MySQL in System Preferences.

MySQL in System Preferences

MySQL in System Preferences


Switched user to root.

$ sudo su


Started MySQL in safe mode.

$ sudo mysqld_safe --skip-grant-tables


I opened another terminal tab/window and lauched mysql shell there.

sh-3.2# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



Changed root password.

mysql> UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE user='root';
Query OK, 0 rows affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 1



And then,

Query OK, 0 rows affected (0.02 sec)




mysql> \q
sh-3.2# exit



Now try logging in with the new password.

$ mysql -u root -p
Enter password:


It works!

Notes: Enable Apache2, PHP5 and Virtual Hosts in Mac OS X

Mac OS X came with Apache2 web server and PHP5 out of the box. All I had to do was enable them.

Enable PHP5:

I edited the Apache configuration file httpd.conf, but first, I made a backup.

$ cd /etc/apache2 
$ sudo cp httpd.conf httpd.conf.bak 
$ sudo nano httpd.conf

I removed the comment symbol “#” from the following line in httpd.conf.

LoadModule php5_module libexec/apache2/

Configure PHP5:

The configuration file for PHP is found in /private/etc/php.ini. I left it untouched and just made a backup.

$ cd /private/etc 
$ sudo cp php.ini php.ini.bak

Enable Virtual Hosts:

I proceeded to remove the comment symbol “#” from the following line in httpd.conf.

Include /private/etc/apache2/extra/httpd-vhosts.conf

Start the Apache Server:

I entered this command from the terminal.

$ sudo apachectl restart

Create a PHP script for testing:

The ~/Sites/ folder is available by default for user specific web sites. I created the following PHP script and saved it as ~/Sites/test.php.

<?php phpinfo(); ?>


I launched the Safari web browser and entered the following in the address bar.


It worked!