答案1
这里有一个大话题: https://stackoverflow.com/questions/7739645/install-mysql-on-ubuntu-without-password-prompt
这样,您可以在安装软件包之前声明密码。
#!/bin/bash
cd /home/userver2
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password 113phantom'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password 113phantom'
sudo apt-get -y install mysql-server