Now let's take into account the automatic deployment of MySQL on Ubuntu. There are several problems to solve:
First, check whether MySQL has been installed.
Second, avoid entering the root password interactively during installation.
Add the function check dpkg package in tool. Sh.
#$1 means the full name of dpkg # return 1 If dpkg is installed (found 'II dpkg-name' in the returned string) # Otherwise return 0 Function hasdpkg {r = 'dpkg-L | grep "$1" 'If [-n "$ R"] thenh = 'dpkg-L | grep "II $1 "'If [-n" $ H "] Then return 1 else return 0fi elsereturn 0 fi}
Only when the string starting with II returned by dpkg-L is deemed to have been installed successfully.
Check the script install. Sh for installation.
#! /Bin/bash source ../common/tool. shmysql = "mysql-server-5.5" hasdpkg $ mysqlr =$? #! /Bin/bash if [$ R-EQ 1] Then ECHO "$ mysql was installed" else echo "$ mysql was not installed" Echo mysql-server/root_password password 1234 | sudo debconf-set-selections echo mysql-server/root_password_again password 1234 | sudo debconf-set-selections apt-Get install $ mysqlfi