1sudo apt install debconf-utils -y
see what possible selections a package may have
1sudo debconf-get-selections | grep mysql
1mysql-server-5.7 mysql-server/root_password password
2mysql-server-5.7 mysql-server/root_password_again password
3mysql-server-5.7 mysql-server/no_upgrade_when_using_ndb error
4mysql-server-5.7 mysql-server/password_mismatch error
5mysql-server-5.7 mysql-server-5.7/start_on_boot boolean true
6mysql-server-5.7 mysql-server-5.7/postrm_remove_databases boolean false
7mysql-server-5.7 mysql-server-5.7/nis_warning note
8mysql-server-5.7 mysql-server-5.7/really_downgrade boolean false
set those selections
1MYSQL_PASS='your_password'
2
3sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_PASS}"
4sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_PASS}"