Only used on localhost so did not feel concerned about the password weakness here
sudo service mysql stop
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'basicPassword1234';" >| $HOME/mysql-init
sudo mysqld --init-file=$HOME/mysql-init &
sudo service mysql start
Then
sudo mysql -p # and type your password here basicPassword1234
sudo service mysql stop
mypassword=$(strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
)
echo ${mypassword} # as it's generated, you need to keep trace of the password to put in your password manager
echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '"${mypassword}"';" >| $HOME/mysql-init
sudo mysqld --init-file=$HOME/mysql-init &
sudo service mysql start
Then
sudo mysql -p # and type generated password here