Home > Database > Mysql Tutorial > How to Automate MySQL Installation on Ubuntu Without Password Prompt?

How to Automate MySQL Installation on Ubuntu Without Password Prompt?

Patricia Arquette
Release: 2024-11-17 03:57:03
Original
895 people have browsed it

How to Automate MySQL Installation on Ubuntu Without Password Prompt?

Automating MySQL Installation on Ubuntu without Password Prompt

In Ubuntu, installing MySQL server using sudo apt-get install mysql requires manual password entry. However, this is impractical for scripting purposes. To automate the installation and eliminate the interactive password prompt, we can employ the following approach:

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

This method sets the root password for MySQL server before the installation process begins. Replace your_password with the desired password or leave it blank for a passwordless setup.

For specific MySQL server versions (e.g., 5.6), modify the commands accordingly:

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

For mysql-community-server, use these keys:

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

If your shell does not support here-strings, use echo ... | sudo debconf-set-selections or the following alternative:

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

You can verify the set password using sudo debconf-get-selections | grep ^mysql. This technique allows you to automate MySQL server installation on Ubuntu without the need for user interaction during the password setup.

The above is the detailed content of How to Automate MySQL Installation on Ubuntu Without Password Prompt?. 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