Installing Percona/MySQL unattended on Ubuntu

后端 未结 5 1588
闹比i
闹比i 2020-12-28 08:29

I can install MYSQL on Ubuntu without prompts with the code below:

dbpass=\"mydbpassword\"
export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.1 mysql-         


        
相关标签:
5条回答
  • 2020-12-28 09:05

    If you understand what is going on underneath the hood it makes it easier to debug and figure out why this isn't working.

    When you install a debian package often times you get questions about licenses, passwords, locations, etc. All of those values are stored in debconf. If you are wanting to do an unattended installation you can preload those answers into debconf so you aren't prompted for those questions, since they are already answered.

    The challenge comes when understanding how to properly answer those questions. To do this you first need to install the debconf-utils

    apt install debconf-utils

    next you need to manually install your package.

    In my case I am installing the percona-xtradb-cluster-57 package.

    wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
    sudo dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
    sudo apt-get update -y
    sudo apt-get install -y percona-xtradb-cluster-57
    

    After this has been installed you can get the selections that have been set by using the deb-get-selections tool.

    debconf-get-selections | grep percona
    

    In the response you will see the selections that were set. In this case

    percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/root-pass password
    percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/re-root-pass  password
    percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/remove-data-dir   boolean false
    percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/root-pass-mismatch    error
    percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/data-dir  note
    

    You can now copy the values that you want to set. In my case I want automatically set the root password.

    In your automated installation script you can now use the debconf-set-selections tool to automate setting the values for the root password question and the confirm root password question.

    echo "percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/root-pass password my_temp_password" | debconf-set-selections
    echo "percona-xtradb-cluster-server-5.7   percona-xtradb-cluster-server-5.7/re-root-pass  password my_temp_password" | debconf-set-selections
    

    Happy Automating!

    0 讨论(0)
  • 2020-12-28 09:14

    Think I figured it out

    echo "percona-server-server-5.5 mysql-server/root_password password mypassword" | debconf-set-selections
    echo "percona-server-server-5.5 mysql-server/root_password_again password mypassword" | debconf-set-selections
    

    Don't use export DEBIAN_FRONTEND=noninteractive. If the debconf entries are correct, then you won't be prompted anyway. If they are incorrect and you use noninteractive then the prompt will continue with a blank password.

    Since Percona 'hooks into' MySQL check that it installed correctly using

    service mysql status
    

    and you will know it is percona if you see something like

    mysql.service - LSB: Start and stop the mysql (Percona Server) daemon

    Then finally check the password was set correctly

    mysql -u user -pmypassword
    

    EDIT: That said, for a newer version of percona, F21's answer worked for me. You can check the entries in /var/cache/debconf/passwords.dat

    0 讨论(0)
  • 2020-12-28 09:15

    The second part of the debconf-prefix should not contain the version number:

    echo percona-server-server-5.5 percona-server-server/root_password password $dbpass | sudo debconf-set-selections
    echo percona-server-server-5.5 percona-server-server/root_password_again password $dbpass | sudo debconf-set-selections
    

    For 5.6:

    echo percona-server-server-5.6 percona-server-server/root_password password $dbpass | sudo debconf-set-selections
    echo percona-server-server-5.6 percona-server-server/root_password_again password $dbpass | sudo debconf-set-selections
    
    0 讨论(0)
  • 2020-12-28 09:19

    I actually found that the answer here install mysql on ubuntu without password prompt that suggested

    export DEBIAN_FRONTEND=noninteractive apt-get -q -y install mysql-server

    Worked and left me with a root user with no password, which is what I wanted.

    0 讨论(0)
  • 2020-12-28 09:22

    you can always do normal installation and then script:

    • killing mysql server
    • starting it with skip-grant-tables
    • adjusting passwords
    • killing the temporarily started mysql without authentication
    • starting regular mysql
    0 讨论(0)
提交回复
热议问题