-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql
35 lines (33 loc) · 898 Bytes
/
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
32
33
34
35
# @IgnoreInspection BashAddShebang
# Written by Legioner <[email protected]>
# Created : 2016.08.20
# Last updated : 2016.08.20
# Version : 1.0
#
# Description : mysql/mariadb related utility functions
# Function will check if there is access to provided host db
# Usage example : [[ $(database_is_operational "db_user" "db_password" "db_host") ]]
# Args:
# $1 - database username
# $2 - password of database user
# $3 - database host
# Returns : true if database is reachable
function database_is_operational() {
local user=$1
local password=$2
local host=$3
mysqladmin ping -u${user} -p ${password} -h ${host} --silent
}
function wait_for_database() {
local user=$1
local password=$2
local host=$3
local retries=10
while ! $(database_is_operational ${user} ${password} ${host}); do
[[ ${i} -eq 0 ]] && {
exit 1
}
let i=i-1
sleep 5
done
}