Home >Database >Mysql Tutorial >How can I automate a silent MySQL installation on Ubuntu and set a specific root password?

How can I automate a silent MySQL installation on Ubuntu and set a specific root password?

Linda Hamilton
Linda HamiltonOriginal
2024-11-18 20:49:02499browse

How can I automate a silent MySQL installation on Ubuntu and set a specific root password?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn