How can I install MySQL on Ubuntu without having to enter a password during the process?
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.
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!