How to write a script to install MySQL server on Ubuntu?
sudo apt-get install mysql will install, but also ask for a password to be entered in the console.
How to do this in a non-interactive way? That is, write a script that can provide the password?
#!/bin/bash
sudo apt-get install mysql # To install mysql server
# How to write script for assigning password to mysql root user
# End
解决方案
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
Replace your_password with the desired root password. (it seems your_password can also be left blank for a blank root password.)
If your shell doesn't support here-strings (zsh, ksh93 and bash support them), use:
echo ... | sudo debconf-set-selections