Automating MySQL Installation on Ubuntu without Password Prompts
Installing MySQL server on Ubuntu using the command sudo apt-get install mysql requires a password to be entered manually. To streamline this process and eliminate the need for user interaction, a script can be created to provide the password automatically.
Script Syntax
The following script will install MySQL server and assign a custom password to the root user:
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
Explanation
Specific Version Support
For specific MySQL versions, such as 5.6, specify the version in the configuration keys:
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
For MySQL Community Server, the configuration 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
Alternative Shell Syntax
If your script is using a non-bash shell, use the following syntax to pass multiline strings:
echo ... | sudo debconf-set-selections
Or, using heredocs (requires bash, zsh, or ksh93 shell):
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
Verification
To check if the configuration was set correctly, run the following command:
sudo debconf-get-selections | grep ^mysql
This should output the values set for the MySQL configuration keys.
Das obige ist der detaillierte Inhalt vonWie automatisiere ich die MySQL-Installation unter Ubuntu ohne Passwortabfrage?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!