Automating MySQL Installation on Ubuntu without Password Prompt
In Ubuntu, installing MySQL server using sudo apt-get install mysql requires manual password entry. However, this is impractical for scripting purposes. To automate the installation and eliminate the interactive password prompt, we can employ the following approach:
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
This method sets the root password for MySQL server before the installation process begins. Replace your_password with the desired password or leave it blank for a passwordless setup.
For specific MySQL server versions (e.g., 5.6), modify the commands accordingly:
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, use these keys:
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
If your shell does not support here-strings, use echo ... | sudo debconf-set-selections or the following alternative:
cat << EOF | sudo debconf-set-selections mysql-server mysql-server/root_password password your_password mysql-server mysql-server/root_password_again password your_password EOF
You can verify the set password using sudo debconf-get-selections | grep ^mysql. This technique allows you to automate MySQL server installation on Ubuntu without the need for user interaction during the password setup.
The above is the detailed content of How to Automate MySQL Installation on Ubuntu Without Password Prompt?. For more information, please follow other related articles on the PHP Chinese website!