Non-Interactive Installation of MySQL on Ubuntu
The standard method of installing MySQL server on Ubuntu using sudo apt-get install mysql prompts for a password in the console, which can be inconvenient when writing scripts for automated installations.
Using debconf-set-selections
To avoid the password prompt during installation, you can use the debconf-set-selections command to preconfigure the password for the MySQL root user. This requires the following steps:
sudo debconf-set-selectionsIn this script, replace your_password with the desired root password. Note: it is also possible to leave your_password blank to set the root password to empty.
Specific MySQL Versions
If you need to install a specific version of MySQL, such as MySQL 5.6, specify the version in the debconf-set-selections command as follows:
sudo debconf-set-selectionsMySQL Community Server
For MySQL community editions, the debconf-set-selections keys differ slightly:
sudo debconf-set-selectionsHere-Strings in Non-Bash Shells
Some shells, such as dash or ash, do not support here-strings. In these cases, use the following:
echo ... | sudo debconf-set-selectionsOr, write multiline strings using:
catVerification
To check the configured root password, use the debconf-get-selections command:
$ sudo debconf-get-selections | grep ^mysql mysql-server mysql-server/root_password_again password your_password mysql-server mysql-server/root_password password your_password
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3