开发者社区 问答 正文

在Ubuntu上安装MySQL而没有密码提示?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

展开
收起
保持可爱mmm 2020-05-17 18:22:47 942 分享 版权
1 条回答
写回答
取消 提交回答
  • 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密码。)

    如果您的外壳不支持此处字符串(zsh,ksh93和bash支持它们),请使用:

    echo ... | sudo debconf-set-selections 来源:stack overflow

    2020-05-17 18:36:30
    赞同 展开评论