On Unix-like systems, you stop the server and start it by specifying init-file. You can save the ALTER USER 'root'@'localhost' IDENTIFIED BY 'New$trongPass1' SQL code in that file. MySQL executes the contents of the file at startup, changing the password of the root user:
- Stop the server:
shell> sudo systemctl stop mysqldshell> pgrep mysqld
- Save the SQL code in /var/lib/mysql/mysql-init-password; make it readable to MySQL only:
shell> vi /var/lib/mysql/mysql-init-passwordALTER USER 'root'@'localhost' IDENTIFIED BY 'New$trongPass1';shell> sudo chmod 400 /var/lib/mysql/mysql-init-passwordshell> sudo chown mysql:mysql /var/lib/mysql/mysql-init-password
- Start the MySQL server with the --init-file option and other options ...