Taking care of prompt imputs from a script with Debconf
sudo apt install debconf-utils -y
see what possible selections a package may have
sudo debconf-get-selections | grep mysql
mysql-server-5.7 mysql-server/root_password password
mysql-server-5.7 mysql-server/root_password_again password
mysql-server-5.7 mysql-server/no_upgrade_when_using_ndb error
mysql-server-5.7 mysql-server/password_mismatch error
mysql-server-5.7 mysql-server-5.7/start_on_boot boolean true
mysql-server-5.7 mysql-server-5.7/postrm_remove_databases boolean false
mysql-server-5.7 mysql-server-5.7/nis_warning note
mysql-server-5.7 mysql-server-5.7/really_downgrade boolean false
set those selections
MYSQL_PASS='your_password'
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_PASS}"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_PASS}"