Bash Script Programming fifteen MySQL automatic deployment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.