If you have forgot the MySQL root password, can’t remember or want to break in….. you can reset the mysql database password from the command line in either Linux or macOS Sierra and OSX as long as you know the root user password of the box you are on, this is for MySQL 5.7 onwards:
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and log in without a password as root:
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.
sudo /usr/local/mysql/support-files/mysql.server start
Thats it, now your root password will be updated.