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:

Supported Releases:

Official Reference Documents

官方參考文檔

MySQL

MariaDB

Percona

Thinking

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

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

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

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

Shell Script

Shell腳本內容,已上傳至GitHub

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#!/bin/bash
#Wirter: lempstacker
#Blog: https://lempstacker.com/
#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 '[email protected]*Ver(.*),.*@Ver\[email protected]')$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 '[email protected]*version (.*)\(1\)-release.*@\[email protected]')
[[ ${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 '[email protected]"@@g;[email protected]^PRETTY_NAME=(.*)@\[email protected]' "$releaseFile")
distroName=$(sed -r -n '[email protected]"@@g;[email protected]^ID=(.*)@\[email protected]' "$releaseFile") #debian ubuntu
distroVersion=$(sed -r -n '[email protected]"@@g;[email protected]^VERSION_ID=(.*)@\[email protected]' "$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 [email protected]: 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 [email protected]: 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[email protected]:~# 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 ''.
[email protected]:~# mysql -e 'select version();'
+-----------+
| version() |
+-----------+
| 5.7.15-9 |
+-----------+
[email protected]:~# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.15-9!
[email protected]:~#

Installing MySQL

1
2


Ubuntu Yakkety

Installing MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[email protected]:~# 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.
[email protected]:~# mysql -e 'select version();'
+-------------------------+
| version() |
+-------------------------+
| 5.7.16-0ubuntu0.16.10.1 |
+-------------------------+
[email protected]:~# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.16!
[email protected]:~#

Installing MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[email protected]:~# 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.
[email protected]:~# mysql -e 'select version();'
+--------------------------+
| version() |
+--------------------------+
| 10.1.19-MariaDB-1~xenial |
+--------------------------+
[email protected]:~# bash mysql.sh
Attention: You Have Installed Ver 15.1 Distrib 10.1.19-MariaDB!
[email protected]:~#

CentOS 7

Installing MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[[email protected] ~]# 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.
[[email protected] ~]# mysql -uroot -p -e 'select version();'
Enter password:
Please use --connect-expired-password option or invoke mysql in interactive mode.
[[email protected] ~]# 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.
[[email protected] ~]# bash mysql.sh
Attention: You Have Installed Ver 14.14 Distrib 5.7.16!
[[email protected] ~]#

Installing MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[[email protected] ~]# 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.
[[email protected] ~]# mysql -e 'select version();'
+-----------------+
| version() |
+-----------------+
| 10.0.28-MariaDB |
+-----------------+
[[email protected] ~]# bash mysql.sh
Attention: You Have Installed Ver 15.1 Distrib 10.0.28-MariaDB!
[[email protected] ~]#

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