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

How to Install MySQL on Ubuntu Without Entering a Password?

Mary-Kate Olsen
Release: 2024-11-19 22:47:02
Original
513 people have browsed it

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

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

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

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

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

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!

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