Silent MySQL Installation on Ubuntu
The typical MySQL server installation on Ubuntu via sudo apt-get install mysql prompts for a password. This article demonstrates a solution to automate the installation and password assignment using a script.
Script for Non-Interactive Password Assignment
To provide the password non-interactively, a script can be created with the following commands:
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
Simply substitute your_password with the desired root password. Note that leaving this field blank may result in a blank root password.
Alternative Method for Basic Shells
In certain shells that do not support here-strings, you can use the following syntax:
echo ... | sudo debconf-set-selections
For example, the following command can be used to assign a password to MySQL server version 5.6:
echo 'mysql-server-5.6 mysql-server/root_password password your_password' | sudo debconf-set-selections echo 'mysql-server-5.6 mysql-server/root_password_again password your_password' | sudo debconf-set-selections sudo apt-get -y install mysql-server-5.6
Verification
You can verify the set selections using:
sudo debconf-get-selections | grep ^mysql
This will output the key-value pairs used to assign the root password.
The above is the detailed content of How can I automate a silent MySQL installation on Ubuntu and set a specific root password?. For more information, please follow other related articles on the PHP Chinese website!