With the release of
MySQL 5.6, there was no longer a default user account with an empty password. For security reasons the
root account is now allocated a random password when MySQL is installed, which is written to a log file.
You then look up the password from the log file, and use it to login and change it to something else...
$ sudo grep 'temporary password' /var/log/mysqld.log $ mysqladmin -u root --password=RANDOM_PASSWORD_FROM_LOG password myNewSuperSecretPassword1!
This is all well and good, unless you are automating deployment of MySQL. We use
ansible to spin up our local dev servers, and as soon as we upgraded MySQL, all our MySQL commands started failing as they could no longer authenticate.
There was no obvious way to install with a predefined password, or no password, so we came up with the following to automate setting up MySQL.