To do it in non interactive mode (from a script):
systemctl start mysqld
MYSQL_ROOT_TMP_PSW=$(grep 'temporary password' $logpath/mysqld.log |sed "s|.*: ||")
## POPULATE SCHEMAS WITH ROOT USER
/usr/bin/mysql --connect-expired-password -u root -p${MYSQL_ROOT_TMP_PSW} < "$mysql_init_script"
Here's the head of the init script
SET GLOBAL validate_password_policy=LOW;
FLUSH privileges;
SET PASSWORD = PASSWORD('MYSQL_ROOT_PSW');
FLUSH privileges;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
FLUSH privileges;
...
Then restart the service systemctl restart mysqld