如何将密码从bash脚本传递给aptitude以安装mysql?

我正在编写一个简单的bash脚本来在Ubuntu上安装MySQL。
#!/bin/bash
apt-get update

# Install MySQL5 
aptitude -y install mysql-server mysql-client libmysqlclient15-dev

但MySQL提示输入密码并确认。如何传递root密码?有可以使用的回声吗?

这样更容易

install mysql on ubuntu without password prompt

sudo debconf-set-selections <<< 'mysql-server-5.1 mysql-server/root_password password your_password'
sudo debconf-set-selections <<< 'mysql-server-5.1 mysql-server/root_password_again password your_password'
sudo apt-get -y install mysql-server

如果你的shell不支持这里的字符串(zsh,ksh93和bash支持它们),请使用:

echo ... | sudo debconf-set-selections

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...