MySQL是一款關係型數據庫管理系統,常用於LEMPLAMP開發環境,其變種(variants)有MariaDBPercona等。現通過Shell腳本實現在各GNU/Linux發行版中使用對應的包管理器安裝最新的穩定版MySQL(MariaDB、Percona)。

GNU/Linux發行版包含RHELCentOSDebianUbuntu

Preparation

Variants Doc Page Repo Page
MySQL doc repo
MariaDB doc repo
Percona doc repoV5.6repoV5.7

MySQL、Percona提供針對yum(用於RedHat、CentOS)和apt(用於Debian、Ubuntu)包管理器的倉庫(repo),而MariaDB則針對各GNU/Linux發行版提供對應的倉庫(repo)。

GNU/Linux Distribution Supported

判斷具體GNU/Linux發行版的實現方式參見本人Blog Try To Extract Operation System Info On GNU/Linux Distribution

以下是各DBMS支持的GNU/Linux發行版信息,皆摘自官方文檔。

MySQL Supported

MySQL Yum repository supports the following Linux Distros: * Red Hat Enterprise Linux / Oracle Linux * Fedora

The APT repository supports the following Linux Distros: * Debian - 7 * Debian - 8 * Ubuntu - 12.04 LTS * Ubuntu - 14.04 LTS * Ubuntu - 15.10 – MySQL Repositories

MariaDB Supported

For CentOS, RedHat, and Fedora, it is highly recommended to install from a repository using yum.

We currently have YUM repositories for CentOS 5, CentOS 6, CentOS 7, RHEL 5, RHEL 6, RHEL 7, and Fedora 22, 23 and 24. – Adding the MariaDB YUM Repository

For Debian and Ubuntu, it is highly recommended to install from the repositories, using apt-get, aptitude, synaptic or another package manager. – Installing MariaDB using APT

Percona Supported

Percona provides repositories for yum (RPM packages for Red Hat, CentOS and Amazon Linux AMI) and apt (.deb packages for Ubuntu and Debian) for software such as Percona Server, Percona XtraBackup, and Percona Toolkit. This makes it easy to install and update your software and its dependencies through your operating system’s package manager. This is the recommend way of installing where possible. – Installing Percona Server from Repositories

Supported Releases: * CentOS 6 and RHEL 6 (Current Stable) * CentOS 7 and RHEL 7 * Amazon Linux AMI (works the same as CentOS 6) – Installing Percona Server on Red Hat Enterprise Linux and CentOS

Supported Releases: * Debian: * 7.0 (wheezy) * 8.0 (jessie) * Ubuntu: * 12.04LTS (precise) * 14.04LTS (trusty) * 15.10 (wily) * 16.04LTS (xenial) – Installing Percona Server on Debian and Ubuntu

Official Reference Documents

官方參考文檔

MySQL * MySQL Repositories * Download MySQL Yum Repository * A Quick Guide to Using the MySQL Yum Repository * Download MySQL APT Repository * A Quick Guide to Using the MySQL APT Repository * 2.1.3.2 Signature Checking Using GnuPG * 2.1.3.4 Signature Checking Using RPM * 7.5.2 The Password Validation Plugin

MariaDB * Setting up MariaDB Repositories * Installing MariaDB .deb Files * Import the GnuPG signing key * Installing MariaDB with yum

Percona * Installing Percona Server from Repositories * Installing Percona Server on Red Hat Enterprise Linux and CentOS * Installing Percona Server on Debian and Ubuntu

Thinking

根據各MySQL Variants的官方文檔,針對各GNU/Linux發行版進行腳本編寫。

注意MySQL 5.7安裝安成並啓動後,自動生成臨時密碼,可通過命令

awk '$0~/temporary password/{print $NF}' /var/log/mysqld.log

提取。另首次登入後須更改用戶密碼,否則會報錯,具體操作可見本人另一篇Blog的相關章節 link

Shell Script

Shell腳本內容,已上傳至GitHub

#!/bin/bash
#Wirter: lempstacker
#Blog: https://lempstacker.github.io/
#Date: 2016.10.20 10:24 Thu Asia/Shanghai
#Purpose: Auto Installing MySQL/MariaDB/Percona Via Package Management
#Note: Used Both RedHat/CentOS And Debian/Ubuntu Distribution
# UpdateTime: 2016.12.21 15:56 Wed Asia/Shanghai

# prompt timeout time (second)
timeout=10

# font color
c_black='\e[30m'
c_red='\e[31;1m'
c_green='\e[32m'
c_yellow='\e[33m'
c_blue='\e[34m'
c_purple='\e[35m'
c_cyan='\e[36m' #藍綠色
c_end='\e[0m'

# Check MySQL & MySQL Variants Exists Or Not
if command -v mysql &> /dev/null; then
    printf "Attention: You Have Installed $c_red$(mysql -V | sed -n -r 's@.*Ver(.*),.*@Ver\1@p')$c_end!\n" && exit
fi

#檢測執行腳本時是否是root或擁有sudo權限
#Check Root or Sudo Privilege  root uid is 0
if [[ "$UID" -ne 0 ]]; then
    printf "Sorry, This Script Must Be Runned As $c_red'root'$c_end or $c_red'sodo'$c_end Privilege!\n" && exit 1
fi

#檢測bash版本
#Check Bash Version
bashVersion=$(bash --version | sed -r -n 's@.*version (.*)\(1\)-release.*@\1@p')
[[ ${bashVersion%%.*} -lt 4 ]] && printf "Current bash version is $c_red%s$c_end. Strongly suggest upgrading to versin $c_red"4"$c_end.\n" "$bashVersion"

#獲取GNU/Linux發行版信息
#Get Distro Info
if [[ -f '/etc/redhat-release' ]]; then
    releaseFile='/etc/redhat-release'
    distroFullName=$(cat "$releaseFile")
    distroName=$(rpm -q --qf "%{name}" -f "$releaseFile")
    distroName=${distroName%%-*}
    # centos-release fedora-release redhat-release
    distroVersion=$(rpm -q --qf "%{version}" -f "$releaseFile")   # 7 23
    distroVersion=${distroVersion//Server/}     # used for redhat

elif [[ -f '/etc/os-release' ]]; then
    releaseFile='/etc/os-release'
    distroFullName=$(sed -r -n 's@"@@g;s@^PRETTY_NAME=(.*)@\1@p' "$releaseFile")
    distroName=$(sed -r -n 's@"@@g;s@^ID=(.*)@\1@p' "$releaseFile")     #debian ubuntu
    distroVersion=$(sed -r -n 's@"@@g;s@^VERSION_ID=(.*)@\1@p' "$releaseFile")    #8 16.10
else
    printf $c_red"Sorry, This Script Doesn't Supprot Your Operation System. Bye!$c_end\n"
    exit 2
fi

distroName=${distroName,,}  #transfer to lowercase
printf "Current OS Is $c_red%s$c_end.\n" "$distroFullName"



################ Choose MySQL & MySQL Variants Distribution ################

#Definition 定義相關變量
declare -A dbmsArr    #MySQL發行版清單
dbmsArr=([1]='MySQL' [2]='MariaDB' [3]='Percona' )

# 拼接提示語 concatenate prompt sentences
dbmsSelectPrompt='Please Select MySQL DBMS Distribution:\n'
for (( i = 1; i <= ${#dbmsArr[@]}; i++ )); do
    dbmsSelectPrompt=$dbmsSelectPrompt"$i) ${dbmsArr[$i]}\n"
done

printf "$dbmsSelectPrompt"

itemSelect=''   #set global variable 設置全局變量
dbmsSelectFunc(){
    read -t $timeout -p 'Please Select The Distribution Item No.(eg:1,2,...):' answer
    flag=0  #flat默認爲0,當符合要求時更改爲1,跳出while循環
    while [[ $flag -eq 0 ]]; do
        if [[ "$answer" == "" ]]; then
            printf $c_red'\nMust Input Something, Script Will Exit!\n'$c_end && exit 3
        elif [[ -z ${dbmsArr[$answer]} ]]; then
            printf $c_red'Wrong Distribution Item No. Try Again!\n'$c_end
            dbmsSelectFunc  # 迭代函數自身 iteration function self
        else
            flag=1
            itemSelect=$answer
        fi
    done
}

dbmsSelectFunc

########  Variables  Needed  ########
dbmsSelect=${dbmsArr[$itemSelect]}
dbmsSelectLower=${dbmsSelect,,}
#####################################

printf 'The Distribution You Choose Is '$c_red"$dbmsSelect\n"$c_end

unset dbmsArr
unset dbmsSelectPrompt
unset itemSelect



################ Choose Specific Release Version ################
# MariaDB 10.1 10.0 5.5   MySQL/Percona 5.5 5.6 5.7
declare -A releaseVersionArr    #Release版本清單
case "$dbmsSelectLower" in
    mariadb )
        releaseVersionArr=([1]='10.1' [2]='10.0')
        ;;
    mysql )
        releaseVersionArr=([1]='5.7' [2]='5.6' [3]='8.0')
        ;;
    percona )
        # releaseVersionArr=([1]='5.7' [2]='5.6')
        releaseVersionArr=([1]='5.7')
        ;;
esac

# 拼接提示語 concatenate prompt sentences
versionSelectPrompt='Please Select Specific Release Version:\n'
for (( i = 1; i <= ${#releaseVersionArr[@]}; i++ )); do
    versionSelectPrompt=$versionSelectPrompt"$i) ${releaseVersionArr[$i]}\n"
done

printf "$versionSelectPrompt"

versionItemSelect=''    #set global variable 設置全局變量
versionSelectFunc(){
    read -t $timeout -p 'Please Select Release Version Item No.(eg:1,2,...):' answer
    flag=0
    while [[ $flag -eq 0 ]]; do
        if [[ "$answer" == "" ]]; then
            printf $c_red'\nMust Input Something, Script Will Exit!\n'$c_end && exit 4
        elif [[ -z ${releaseVersionArr[$answer]} ]]; then
            printf $c_red'Wrong Version Item No. Try Again!\n'$c_end
            versionSelectFunc  # 迭代函數自身 iteration function self
        else
            flag=1
            versionItemSelect=$answer
        fi
    done
}

versionSelectFunc

########  Variables  Needed  ########
releaseVersionSelect=${releaseVersionArr[$versionItemSelect]}
#####################################

printf 'The DBMS You Choose Is '$c_red"$dbmsSelect"$c_end"-"$c_red"$releaseVersionSelect"$c_end".\n"

unset releaseVersionArr
unset versionItemSelect



################ Setting Specific Variabless Based on DistroName ################

case "$distroName" in
    redhat|centos )
        ########  Variables  Needed  ########
        [[ $(uname -m) == 'x86_64' ]] && hardwareArch='amd64' || hardwareArch='x86'
        [[ "$distroName" = 'redhat' ]] && os='rhel' || os="$distroName"
        #####################################
        ;;
    debian|ubuntu)
        declare -A codeNameArr    # http://nginx.org/en/linux_packages.html
        if [[ "$distroName" = 'debian' ]]; then
            codeNameArr=([7]='wheezy' [8]='jessie')
        else
            # 相關軟件尚沒有針對Ubuntu 16.10的Repo,將其等效於Ubuntu 16.04
            # codeNameArr=([12.04]='precise' [14.04]='trusty' [16.04]='xenial' [16.10]='yakkety')
            codeNameArr=([12.04]='precise' [14.04]='trusty' [16.04]='xenial' [16.10]='xenial')
        fi
        ########  Variables  Needed  ########
        codename=${codeNameArr[$distroVersion]}
        #####################################
        unset codeNameArr
        ;;
esac


################ Definition Installation Prompt (Success/Fail) ################
successConfiguringRepo() {
    printf "Successfully Configurating $dbmsSelect $releaseVersionSelect Repository!\n"
}

startInstallationPrompt() {
    printf "Begin To Install $dbmsSelect $releaseVersionSelect, Just Be Patient!\n"
}

successInstallationPrompt() {
    printf "Successfully Installed $dbmsSelect $releaseVersionSelect!\nInitial Password Of Account $c_red'root'@'localhost'$c_end Is Empty ''.\n"
}

mysqlSecureInstallationPrompt() {
    printf "Note: You Can Run $c_red""mysql_secure_installation""$c_end To Secure MySQL.\n"
}

failInstallationPrompt() {
    printf "Sorry, Fail To Install $c_red"$dbmsSelect$releaseVersionSelect"$c_end.\n"
}

# successConfiguringRepo   #custom function
# startInstallationPrompt   #custom function
# successInstallationPrompt   #custom function
# mysqlSecureInstallationPrompt   #custom function
# failInstallationPrompt   #custom function



################ Configurating Repository & Installing Via Package Manager ################
case "$distroName" in
    redhat|centos )
        yum -y -q remove mariadb-{server,libs} &> /dev/null #5.5

        case "$dbmsSelectLower" in
            mariadb )
                sourceFile='/etc/yum.repos.d/MariaDB.repo'

                echo -e "# MariaDB $releaseVersionSelect $distroName repository list\n# http://downloads.mariadb.org/mariadb/repositories/\n[mariadb]\nname = MariaDB\nbaseurl = http://yum.mariadb.org/$releaseVersionSelect/$os$distroVersion-$hardwareArch\ngpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB\ngpgcheck=1" > $sourceFile


                yum -q clean all

                successConfiguringRepo   #custom function
                startInstallationPrompt   #custom function

                yum -y -q install MariaDB-server MariaDB-client &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    successInstallationPrompt   #custom function
                    mysqlSecureInstallationPrompt   #custom function
                    service mysql start &> /dev/null
                else
                    failInstallationPrompt   #custom function
                    [[ -f "$sourceFile" ]] && rm -f "$sourceFile"
                    exit 5
                fi
                # MariaDB End
                ;;

            mysql )
                sourceFile='/etc/yum.repos.d/mysql-community.repo'

                echo -e "[mysql-connectors-community]\nname=MySQL Connectors Community\nbaseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/$distroVersion/\$basearch/\nenabled=1\ngpgcheck=0\n\n[mysql-tools-community]\nname=MySQL Tools Community\nbaseurl=http://repo.mysql.com/yum/mysql-tools-community/el/$distroVersion/\$basearch/\nenabled=1\ngpgcheck=0\n\n# Enable to use MySQL $releaseVersionSelect\n[mysql${releaseVersionSelect//./}-community]\nname=MySQL $releaseVersionSelect Community Server\nbaseurl=http://repo.mysql.com/yum/mysql-$releaseVersionSelect-community/el/$distroVersion/\$basearch/\nenabled=1\ngpgcheck=0" > $sourceFile

                yum -q clean all
                successConfiguringRepo   #custom function
                startInstallationPrompt   #custom function

                yum install -y -q mysql-community-{server,client,devel} &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    service mysqld start &> /dev/null

                    case "$releaseVersionSelect" in
                        5.6 )
                            successInstallationPrompt   #custom function
                            mysqlSecureInstallationPrompt   #custom function
                            ;;
                        5.7 )
                            newRootPassword='lemp123'
                            #eg:2016-10-21T06:16:53.869126Z 1 [Note] A temporary password is generated for root@localhost: U6YKfJ1f/All
                            initialRootPassword=$(awk '$0~/temporary password/{print $NF}' /var/log/mysqld.log)
                            printf "Successfully Installed $dbmsSelect $releaseVersionSelect!\nInitial Password Of Superuser Account $c_red'root'@'localhost'$c_end Is $c_red"$initialRootPassword"$c_end\n"

                            # mysql -uroot -p"$initialRootPassword" -e "set global validate_password_policy=0;set global validate_password_length=5;alter user 'root'@'localhost' identified by '$newRootPassword';set global validate_password_policy=1;set global validate_password_length=8;flush privileges;"

                            # printf "Newly Password Of Account $c_red'root'@'localhost'$c_end Is $c_red"$newRootPassword"$c_end\n\n"

                            printf "Note: After Installed, You Must Run\n$c_red""ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';""$c_end\nTo Change The Initial Password Of $c_red'root'@'localhost'$c_end, Otherwise MySQL Will Prompt: \n$c_blue""ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement""$c_end.\n"
                            ;;
                    esac

                else
                    failInstallationPrompt   #custom function
                    [[ -f "$sourceFile" ]] && rm -f "$sourceFile"
                    exit
                fi
                # MySQL End
                ;;

            percona )
                sourceFile='/etc/yum.repos.d/percona-release.repo'
                repoRpmUrl='https://www.percona.com/redir/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm'

                [[ -f "$sourceFile" ]] && yum -y -q reinstall "$repoRpmUrl" &> /dev/null

                yum -y -q install "$repoRpmUrl" &> /dev/null

                [[ -f "$sourceFile" ]] && successConfiguringRepo   #custom function
                startInstallationPrompt   #custom function
                yum -y -q install Percona-Server-server-"${releaseVersionSelect//./}" &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    service mysql start &> /dev/null
                    # successInstallationPrompt   #custom function
                    # mysqlSecureInstallationPrompt   #custom function

                    case "$releaseVersionSelect" in
                        5.6 )
                            successInstallationPrompt   #custom function
                            mysqlSecureInstallationPrompt   #custom function
                            ;;
                        5.7 )
                            # newRootPassword='lemp123'
                            #eg:2016-10-21T06:16:53.869126Z 1 [Note] A temporary password is generated for root@localhost: U6YKfJ1f/All
                            initialRootPassword=$(awk '$0~/temporary password/{print $NF}' /var/log/mysqld.log)
                            printf "Successfully Installed $dbmsSelect $releaseVersionSelect!\nInitial Password Of Superuser Account $c_red'root'@'localhost'$c_end Is $c_red"$initialRootPassword"$c_end\n"

                            printf "Note: After Installed, You Must Run\n$c_red""ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';""$c_end\nTo Change The Initial Password Of $c_red'root'@'localhost'$c_end, Otherwise MySQL Will Prompt: \n$c_blue""ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement""$c_end.\n"
                            ;;
                    esac

                else
                    failInstallationPrompt   #custom function
                    [[ -f "$sourceFile" ]] && rm -rf "$sourceFile"
                    exit
                fi
                # Percona End
                ;;
        esac

        ;;

    debian|ubuntu )

        case "$dbmsSelectLower" in
            mariadb )
                sourceFile='/etc/apt/sources.list.d/mariadb.list'
                # mirror choose Digital Ocean New York
                mirrorUrl='http://nyc2.mirrors.digitalocean.com'

                echo -e "# MariaDB $releaseVersionSelect repository list\n# http://downloads.mariadb.org/mariadb/repositories/\ndeb [arch=amd64,i386] $mirrorUrl/mariadb/repo/$releaseVersionSelect/$distroName $codename main\ndeb-src $mirrorUrl/mariadb/repo/$releaseVersionSelect/$distroName $codename main" > $sourceFile

                successConfiguringRepo   #custom function
                # https://mariadb.com/kb/en/mariadb/installing-mariadb-deb-files/
                # As of Ubuntu 16.04 "Xenial" and Debian Sid, our signing key has changed. The id of the new signing key is 0xF1656F24C74CD1D8
                [[ "$codename" == 'xenial' ]] && aptKeyNum='0xF1656F24C74CD1D8' || aptKeyNum='0xcbcb082a1bb943db'
                apt-get -y --force-yes install software-properties-common &> /dev/null
                apt-key adv --recv-keys --keyserver keyserver.ubuntu.com "$aptKeyNum" &> /dev/null
                unset aptKeyNum
                unset mirrorUrl

                # Disable Interactive Prompt Setting Root Password 禁用交互模式,會跳出密碼設置界面
                export DEBIAN_FRONTEND=noninteractive
                debconf-set-selections <<< 'mariadb-server mysql-server/root_password password PASS'
                debconf-set-selections <<< 'mariadb-server mysql-server/root_password_again password PASS'

                apt-get update &> /dev/null
                startInstallationPrompt   #custom function

                apt-get -y --force-yes install mariadb-server &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    service mysql start &> /dev/null
                    # 設置密碼爲空
                    mysql -uroot -pPASS -e "SET PASSWORD = PASSWORD('');"
                    successInstallationPrompt   #custom function
                    mysqlSecureInstallationPrompt   #custom function

                else
                    failInstallationPrompt   #custom function
                    [[ -f "$sourceFile" ]] && rm -f "$sourceFile"
                    unset sourceFile
                    exit
                fi

                unset sourceFile
                #MariaDB End
                ;;

            mysql )
                # [[ ! -f '/usr/bin/curl' ]] && apt-get -y --force-yes intall curl &> /dev/null
                sourceFile='/etc/apt/sources.list.d/mysql.list'

                echo -e "deb http://repo.mysql.com/apt/$distroName/ $codename mysql-$releaseVersionSelect\ndeb http://repo.mysql.com/apt/$distroName/ $codename connector-python-2.0" > $sourceFile

                # http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#repo-qg-apt-repo-manual-setup
                apt-key adv --keyserver pgp.mit.edu --recv-keys 5072E1F5 &> /dev/null

                successConfiguringRepo   #custom function

                apt-get  -y --force-yes autoremove &> /dev/null
                apt-get  -y --force-yes update &> /dev/null

                # 禁用交互模式,會跳出密碼設置界面
                export DEBIAN_FRONTEND=noninteractive
                debconf-set-selections <<< 'mysql-community-server mysql-server/root_password password PASS'
                debconf-set-selections <<< 'mysql-community-server mysql-server/root_password_again password PASS'

                startInstallationPrompt   #custom function
                apt-get -y --force-yes install mysql-server &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    service mysql start &> /dev/null
                    # 設置密碼爲空
                    mysql -uroot -pPASS -e "SET PASSWORD = PASSWORD('');"
                    successInstallationPrompt   #custom function
                    case "$releaseVersionSelect" in
                        5.6 )
                            mysqlSecureInstallationPrompt   #custom function
                            ;;
                    esac
                else
                    failInstallationPrompt   #custom function
                    [[ -f "$sourceFile" ]] && rm -f "$sourceFile"
                    exit
                fi

                #MySQL End
                ;;

            percona )
                command -v curl > /dev/null  || apt-get -y --force-yes intall curl &> /dev/null
                # [[ ! -f '/usr/bin/curl' ]] && apt-get -y -q intall curl &> /dev/null
                tempDebPath='/tmp/percona-release.deb'

                curl -# -o "$tempDebPath" https://repo.percona.com/apt/percona-release_0.1-4."$codename"_all.deb
                [[ -f "$tempDebPath" ]] && dpkg -i "$tempDebPath" && successConfiguringRepo   #custom function
                apt-get update &> /dev/null
                startInstallationPrompt   #custom function

                export DEBIAN_FRONTEND=noninteractive
                debconf-set-selections <<< 'percona-server-server mysql-server/root_password password PASS'
                debconf-set-selections <<< 'percona-server-server mysql-server/root_password_again password PASS'

                apt-get -y --force-yes install percona-server-server-"$releaseVersionSelect" &> /dev/null

                if [[ -f '/usr/bin/mysql' ]]; then
                    service mysql start &> /dev/null
                    mysql -uroot -pPASS -e "SET PASSWORD = PASSWORD('');"
                    successInstallationPrompt   #custom function
                else
                    failInstallationPrompt   #custom function
                fi
                #Percona End
                ;;
        esac

        ;;
esac


#Code End

Testing

在VPS主機測試

Debian Jessie

Installing Percona

root@JessiePercona:~# bash mysql.sh
Current OS Is Debian GNU/Linux 8 (jessie).
Please Select MySQL DBMS Distribution:
1) MySQL
2) MariaDB
3) Percona
Please Select The Distribution Item No.(eg:1,2,...):3
The Distribution You Choose Is Percona
Please Select Specific Release Version:
1) 5.7
Please Select Release Version Item No.(eg:1,2,...):1
The DBMS You Choose Is Percona-5.7.
######################################################################## 100.0%
Selecting previously unselected package percona-release.
(Reading database ... 35397 files and directories currently installed.)
Preparing to unpack /tmp/percona-release.deb ...
Unpacking percona-release (0.1-4.jessie) ...
Setting up percona-release (0.1-4.jessie) ...
Successfully Configurating Percona 5.7 Repository!
Begin To Install Percona 5.7, Just Be Patient!
mysql: [Warning] Using a password on the command line interface can be insecure.
Successfully Installed Percona 5.7!
Initial Password Of Account 'root'@'localhost' Is Empty ''.
root@JessiePercona:~# mysql -e 'select version();'
+-----------+
| version() |
+-----------+
| 5.7.15-9  |
+-----------+
root@JessiePercona:~# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.15-9!
root@JessiePercona:~#

Installing MySQL


Ubuntu Yakkety

Installing MySQL

root@YakketyMySQL:~# bash mysql.sh
Current OS Is Ubuntu 16.10.
Please Select MySQL DBMS Distribution:
1) MySQL
2) MariaDB
3) Percona
Please Select The Distribution Item No.(eg:1,2,...):1
The Distribution You Choose Is MySQL
Please Select Specific Release Version:
1) 5.7
2) 5.6
3) 8.0
Please Select Release Version Item No.(eg:1,2,...):2
The DBMS You Choose Is MySQL-5.6.
Successfully Configurating MySQL 5.6 Repository!
Begin To Install MySQL 5.6, Just Be Patient!
mysql: [Warning] Using a password on the command line interface can be insecure.
Successfully Installed MySQL 5.6!
Initial Password Of Account 'root'@'localhost' Is Empty ''.
Note: You Can Run mysql_secure_installation To Secure MySQL.
root@YakketyMySQL:~# mysql -e 'select version();'
+-------------------------+
| version()               |
+-------------------------+
| 5.7.16-0ubuntu0.16.10.1 |
+-------------------------+
root@YakketyMySQL:~# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.16!
root@YakketyMySQL:~#

Installing MariaDB

root@YakketyMariaDB:~# bash mysql.sh
Current OS Is Ubuntu 16.10.
Please Select MySQL DBMS Distribution:
1) MySQL
2) MariaDB
3) Percona
Please Select The Distribution Item No.(eg:1,2,...):2
The Distribution You Choose Is MariaDB
Please Select Specific Release Version:
1) 10.1
2) 10.0
Please Select Release Version Item No.(eg:1,2,...):1
The DBMS You Choose Is MariaDB-10.1.
Successfully Configurating MariaDB 10.1 Repository!
Begin To Install MariaDB 10.1, Just Be Patient!
Successfully Installed MariaDB 10.1!
Initial Password Of Account 'root'@'localhost' Is Empty ''.
Note: You Can Run mysql_secure_installation To Secure MySQL.
root@YakketyMariaDB:~# mysql -e 'select version();'
+--------------------------+
| version()                |
+--------------------------+
| 10.1.19-MariaDB-1~xenial |
+--------------------------+
root@YakketyMariaDB:~# bash mysql.sh
Attention: You Have Installed Ver 15.1 Distrib 10.1.19-MariaDB!
root@YakketyMariaDB:~#

CentOS 7

Installing MySQL

[root@CentOS7MySQL ~]# bash mysql.sh
Current OS Is CentOS Linux release 7.2.1511 (Core) .
Please Select MySQL DBMS Distribution:
1) MySQL
2) MariaDB
3) Percona
Please Select The Distribution Item No.(eg:1,2,...):1
The Distribution You Choose Is MySQL
Please Select Specific Release Version:
1) 5.7
2) 5.6
3) 8.0
Please Select Release Version Item No.(eg:1,2,...):1
The DBMS You Choose Is MySQL-5.7.
Successfully Configurating MySQL 5.7 Repository!
Begin To Install MySQL 5.7, Just Be Patient!
Successfully Installed MySQL 5.7!
Initial Password Of Superuser Account 'root'@'localhost' Is U(teaVlYa92y
Note: After Installed, You Must Run
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
To Change The Initial Password Of 'root'@'localhost', Otherwise MySQL Will Prompt:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
[root@CentOS7MySQL ~]# mysql -uroot -p -e 'select version();'
Enter password:
Please use --connect-expired-password option or invoke mysql in interactive mode.
[root@CentOS7MySQL ~]# mysql -uroot -p --connect-expired-password -e 'select version();'
Enter password:
ERROR 1820 (HY000) at line 1: You must reset your password using ALTER USER statement before executing this statement.
[root@CentOS7MySQL ~]# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.16!
[root@CentOS7MySQL ~]#

Installing MariaDB

[root@CentOS7MariaDB ~]# bash mysql.sh
Current OS Is CentOS Linux release 7.2.1511 (Core) .
Please Select MySQL DBMS Distribution:
1) MySQL
2) MariaDB
3) Percona
Please Select The Distribution Item No.(eg:1,2,...):2
The Distribution You Choose Is MariaDB
Please Select Specific Release Version:
1) 10.1
2) 10.0
Please Select Release Version Item No.(eg:1,2,...):2
The DBMS You Choose Is MariaDB-10.0.
Successfully Configurating MariaDB 10.0 Repository!
Begin To Install MariaDB 10.0, Just Be Patient!
Successfully Installed MariaDB 10.0!
Initial Password Of Account 'root'@'localhost' Is Empty ''.
Note: You Can Run mysql_secure_installation To Secure MySQL.
[root@CentOS7MariaDB ~]# mysql -e 'select version();'
+-----------------+
| version()       |
+-----------------+
| 10.0.28-MariaDB |
+-----------------+
[root@CentOS7MariaDB ~]# bash mysql.sh
Attention: You Have Installed Ver 15.1 Distrib 10.0.28-MariaDB!
[root@CentOS7MariaDB ~]#

References

Change Logs

  • 2016.11.14 11:26 Mon Asia/Shanghai
    • 初稿完成
  • 2016.12.21 16:01 Wed Asia/Shanghai
    • 腳本優化

  • Note Time: 2016.11.14 11:26 Mon
  • Note Location: Asia/Shanghai
  • Writer: lempstacker