macOS might be the easiest platform to install MySQL on. To do so, simply download the MySQL installation package from the MySQL Download site. I like to use the third link (the DMG).
Once downloaded, run the package. The package will ask you a few questions and you can easily just select the default choice during the installation process.
Once installed, you’ll be prompted that a temporary password has been used for your MySQL instance.
The password will get you in the first time, so you can change it. Once you have documented the password, open System Preferences and click on MySQL in the bottom row of System Preference Panes.
Click Start MySQL Server and then when prompted, authenticate to the system. If you’d like to do this programmatically and don’t need the System Preference pane, you can do so with homebrew. If you have homebrew installed, simply run the brew command with the install verb and mysql as the package:
brew install mysql
Whichever way you install SQL, once installed, you’ll want to set the root password to something other than the intuitionally difficult to remember password provided at install time. To do so, first connect to the mysql instance now running on your computer. As the tools are installed in /usr/local/mysql/bin, run the following:
/usr/local/mysql/bin/mysql -u root
Then, set the password using the ALTER statement along with the USER option and then the username followed by IDENTIFIED BY and ultimately the password, as follows:
ALTER USER 'root'@'localhost' IDENTIFIED BY
'mysupersecretpassword';
Once done, you’ll then be able to connect to mysql normally.