"일꾼이 일을 잘하려면 먼저 도구를 갈고 닦아야 한다." - 공자, 『논어』.
첫 장 > 프로그램 작성 > How can I install MySQL on Ubuntu without a password prompt?

How can I install MySQL on Ubuntu without a password prompt?

2025-02-06에 게시되었습니다
검색:222

How can I install MySQL on Ubuntu without a password prompt?

Non-Interactive Installation of MySQL on Ubuntu

The standard method of installing MySQL server on Ubuntu using sudo apt-get install mysql prompts for a password in the console, which can be inconvenient when writing scripts for automated installations.

Using debconf-set-selections

To avoid the password prompt during installation, you can use the debconf-set-selections command to preconfigure the password for the MySQL root user. This requires the following steps:

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

In this script, replace your_password with the desired root password. Note: it is also possible to leave your_password blank to set the root password to empty.

Specific MySQL Versions

If you need to install a specific version of MySQL, such as MySQL 5.6, specify the version in the debconf-set-selections command as follows:

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

MySQL Community Server

For MySQL community editions, the debconf-set-selections keys differ slightly:

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

Here-Strings in Non-Bash Shells

Some shells, such as dash or ash, do not support here-strings. In these cases, use the following:

echo ... | sudo debconf-set-selections 

Or, write multiline strings using:

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

Verification

To check the configured root password, use the debconf-get-selections command:

$ sudo debconf-get-selections | grep ^mysql
mysql-server    mysql-server/root_password_again    password    your_password
mysql-server    mysql-server/root_password  password    your_password
최신 튜토리얼 더>

부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.

Copyright© 2022 湘ICP备2022001581号-3