"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How can I install MySQL on Ubuntu without a password prompt?

How can I install MySQL on Ubuntu without a password prompt?

Posted on 2025-02-06
Browse:822

How can I install MySQL on Ubuntu without a password prompt?

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-selections 

In 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-selections 

MySQL Community Server

For MySQL community editions, the debconf-set-selections keys differ slightly:

sudo debconf-set-selections 

Here-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-selections 

Or, write multiline strings using:

cat 

Verification

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
Latest tutorial More>

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