Install MySQL on Ubuntu without a password prompt

后端 未结 4 1465
死守一世寂寞
死守一世寂寞 2020-11-27 09:04

How do I write a script to install MySQL server on Ubuntu?

sudo apt-get install mysql will install, but it will also ask for a password to be entered in

4条回答
  •  清酒与你
    2020-11-27 09:29

    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
    

    For specific versions, such as mysql-server-5.6, you'll need to specify the version in like this:

    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
    

    For mysql-community-server, the keys are slightly different:

    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
    

    Replace your_password with the desired root password. (it seems your_password can also be left blank for a blank root password.)

    If your shell doesn't support here-strings (zsh, ksh93 and bash support them), use:

    echo ... | sudo debconf-set-selections 
    

提交回复
热议问题