Home > Database > Mysql Tutorial > body text

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

Linda Hamilton
Release: 2024-11-18 20:49:02
Original
432 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

Verification

You can verify the set selections using:

sudo debconf-get-selections | grep ^mysql
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template