-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-mysql
executable file
·92 lines (80 loc) · 1.94 KB
/
docker-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
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
#!/bin/bash
work_dir=$(readlink -f $(dirname $0))
mode=$1
user=${MYSQL_LOGIN_USERNAME:-root}
master_port=13306
slave1_port=13316
usage() {
cat <<__USAGE__
docker-mysql <sub-command>
sub-command:
master:
connect to master mysql server
slave1:
connect to slave1 mysql server
start:
start all mysql server
stop:
stop all mysql server
alter:
alter <hostname> <sql file>
__USAGE__
}
alter() {
local host=$1
local sql=$2
if [[ -f $sql ]] ; then
echo "Could not find alter sql file. ($sql)"
exit 1
fi
case $host in
master)
mysql -u $user -h 127.0.0.1 -P $master_port < $sql
;;
slave1)
mysql -u $user -h 127.0.0.1 -P $slave1_port < $sql
;;
*)
echo "unknown host: $host."
exit 1;
esac
}
case $mode in
master)
mysql -u $user -h 127.0.0.1 -P $master_port
;;
slave1)
mysql -u $user -h 127.0.0.1 -P $slave1_port
;;
start)
cd $work_dir
mkdir -p sqls
echo "docker run mysql-master"
./master/start-master.sh
echo "docker run mysql-slave1"
./slave1/start-slave1.sh
echo "initdb"
for sql in `find sqls ! -path sqls`
do
echo -n "which database exec $sql (please input databasename)? > "
read dbname
mysql -u root -h 127.0.0.1 -P $master_port -e "create database $dbname"
mysql -u root -h 127.0.0.1 -P $master_port $dbname < $sql
done
echo "finished"
;;
stop)
echo "docker rm mysql-master"
docker rm -f mysql-master
echo "docker rm mysql-slave1"
docker rm -f mysql-slave1
;;
alter)
echo "start alter"
alter $2 $3
;;
*)
echo "you should specify first argument that is mode such as a 'master' or 'slave1'."
exit 1
;;
esac