【发布时间】:2015-10-26 14:48:22
【问题描述】:
我的操作系统是 CentOS 6.6,我想知道如何通过 shell 脚本自动安装 mysql-server。
我发现有一个话题谈到了同样的问题,但在 CentOS 6 上失败了:install mysql on ubuntu without password prompt
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password'
错误信息是
bash: debconf-set-selections: command not found
这是我的基本脚本
#!/bin/sh
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
#password setting
root_password='abc123'
#install mysql-server
yum install mysql mysql-server
#start service
service mysqld start
#MySQL Initial Setup
mysql_secure_installation
#This command needs root password and answers(y/n) for secure questions
是否有任何方法可以自动填写 root 密码并对大多数安全问题回答“y”。
或者它有替代方法来实现相同的目标。即自动安装 myaql-server 且无需密码提示的脚本。
非常感谢您的帮助。
【问题讨论】:
-
请注意,debconf-utils 是仅用于基于 Debian 的发行版的软件包。这就是命令失败的原因。
标签: mysql linux bash shell centos