Home  >  Article  >  Database  >  How to Install MySQL on Ubuntu Without Entering a Password?

How to Install MySQL on Ubuntu Without Entering a Password?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-19 22:47:02436browse

How to Install MySQL on Ubuntu Without Entering a Password?

Passwordless MySQL Installation on Ubuntu

Question:

How can I install MySQL on Ubuntu without having to enter a password during the process?

Background:

Installing MySQL using sudo apt-get install mysql prompts for password input, which can be inconvenient in non-interactive scenarios or when scripting the installation.

Solution:

To bypass the password prompt, use the following script:

#!/bin/bash
sudo debconf-set-selections << EOF
mysql-server mysql-server/root_password password your_password
mysql-server mysql-server/root_password_again password your_password
EOF
sudo apt-get -y install mysql-server

Replace your_password with your desired password. For specific versions (e.g., mysql-server-5.6), specify the version as shown below:

sudo debconf-set-selections << EOF
mysql-server-5.6 mysql-server/root_password password your_password
mysql-server-5.6 mysql-server/root_password_again password your_password
EOF
sudo apt-get -y install mysql-server-5.6

For mysql-community-server, use the following keys:

sudo debconf-set-selections << EOF
mysql-community-server mysql-community-server/root-pass password your_password
mysql-community-server mysql-community-server/re-root-pass password your_password
EOF
sudo apt-get -y install mysql-community-server

You can also use debconf-get-selections to verify your settings:

sudo debconf-get-selections | grep ^mysql

The above is the detailed content of How to Install MySQL on Ubuntu Without Entering a 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