在Ubuntu上安装MySQL而没有密码提示

如何编写脚本在Ubuntu上安装MySQL服务器?

sudo apt-get install mysql 将安装,但同时还会要求您在控制台中输入密码。

如何以非交互方式进行此操作?也就是说,写一个可以提供密码的脚本吗?

#!/bin/bash

sudo apt-get install mysql # To install MySQL server

# How to write script for assigning password to MySQL root user

# End

回答:

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'

sudo apt-get -y install mysql-server

对于特定版本,例如mysql-server-5.6,您需要像这样指定版本:

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password your_password'

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password your_password'

sudo apt-get -y install mysql-server-5.6

对于mysql-community-server,密钥略有不同:

sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/root-pass password your_password'

sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/re-root-pass password your_password'

sudo apt-get -y install mysql-community-server

将your_password替换为所需的root密码。(似乎your_password也可以留空以获取空白的root密码。)

如果您的外壳不支持 此处字符串zshksh93bash 支持它们),请使用:

echo ... | sudo debconf-set-selections

以上是 在Ubuntu上安装MySQL而没有密码提示 的全部内容, 来源链接: utcz.com/qa/414454.html

回到顶部