场景:想通过linux的shell命令自动安装mysql,但是在线安装的时候需要输入user为root的密码,还需要再次输入,就不能实现全自动,因此需要预配置密码。
通过debconf-set-selections可以为自动安装mysql预配置密码
具体用法如下:
#MySQL 5.7
#尽管可以将密码配置为空,但安装过程将自动启用身份验证插件auth_socket .因此,无密码登录必须以基于UNIX套接字的身份验证为条件(例如,要求从本地计算机上的用户帐户root进行登录).
#(1)对于 MySQL APT提供的软件包仓库:
sudo debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass your_password "
sudo debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass your_password "
#(2)对于 Ubuntu软件包存储库提供的软件包:
sudo debconf-set-selections <<< "mysql-server mysql-server/root-password your_password "
sudo debconf-set-selections <<< "mysql-server mysql-server/root-password_again your_password "