export DEBIAN_FRONTEND=noninteractive
sudo -E apt-get -q -y install mysql-server

然后修改密码可以执行下面一行:

mysqladmin -u root password mysecretpasswordgoeshere

还有一种方法貌似用的最多:

echo "mysql-server-5.5 mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password root" | debconf-set-selections
apt-get -y install mysql-server-5.5

其中,中间的password可以留空,MySQL的root用户密码为

一个传送门:https://onebox.site/archives/68.html#数据库创建一个拥有全部权限的用户