How to Change MySql Password from Terminal (for Mac)
First you need to close MySQL. You can go from menus manually or do it from terminal. Here are both ways:
1- First go to Apple icon on the top left corner, open System Preferences. From the menu opened click mySQL on the bottom section. And press stop MySQL Server.
2- From terminal (EASIERRR)
~$ sudo /usr/local/mysql/support-files/mysql.server stop
If you get this error -> “ERROR! MySQL server PID file could not be found!” it means it is already closed
Open in Safe Mode
After stopping mySQL, we should start it in safe mode so that it will give us permission to change password.
~$ sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
Change The Password
Open a new terminal window (You can use shortcut Cmnd+N)
~$ sudo /usr/local/mysql/bin/mysql -u root
It will open mysql now. Now on the sql command line:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass') -> WHERE User = 'root' AND Host = 'localhost'; mysql> FLUSH PRIVILEGES; mysql> \q
Change the MyNewPass part with the password you want. Done! You all set. Now you can start mySQL.
PS: For those who don’t know: “~$”, “mysql>”, “->” parts, you will not include them in commands.