mysql - 使用预定义的 root 密码安装脚本 LAMP

标签 mysql bash ubuntu lamp debconf

我想编写以下 Bash 脚本:

像这样安装 LAMP 时,它会询问我安装 MySQL 的 root 密码。 我想编写 bash 脚本。

sudo apt-get install lamp-server^

我可以这样将变量作为参数传递,这样它就不会在安装过程中询问我吗?

rootPassword="MyRootPassword";

sudo apt-get install lamp-server^ -y $rootPassword

最佳答案

为了以非交互方式回答 debconf 问题,您需要 debconf-utils 包。 debconf-set-selections 命令可用于将通常以交互方式询问的内容手动插入到 debconf 数据库中。这也可以在操作系统安装时使用 FAI 或预置来完成。

export DEBIAN_FRONTEND=noninteractive
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password select PASSWORD'
debconf-set-selections < 'mysql-server-5.1 mysql-server/root_password_again select PASSWORD'

您可能需要将 mysql-server 包名称更改为您的发行版使用的版本。请注意,包“mysql”是一个虚拟包,它指向真实包(包括版本号)。

关于mysql - 使用预定义的 root 密码安装脚本 LAMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8648828/

相关文章:

windows - 使用 Cygwin 进行 FFMPEG 构建错误 cmp : command not found

linux - 读取不同的字段并传递给 awk 以提取这些字段

c++ - 编译boost c++代码错误

ruby - 如何在 Ubuntu 10.04 服务器上安装 Jekyll?

MySQL 触发器在插入后未触发

php - 使用 mysql 存储函数和选择查询

linux - 将程序的输出重定向到旋转文件

c# - SQLException : Server does not exist or connection refused

PHP/MySQL 编辑数据库和调用值

java - 忽略异常,继续插入其余数据