forked from PyMySQL/PyMySQL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.travis.initialize.db.sh
executable file
·51 lines (49 loc) · 2.34 KB
/
.travis.initialize.db.sh
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
#!/bin/bash
#debug
set -x
#verbose
set -v
if [ ! -z "${DB}" ]; then
# disable existing database server in case of accidential connection
mysql -u root -e 'drop user travis@localhost; drop user root@localhost; drop user travis; create user super@localhost; grant all on *.* to super@localhost with grant option'
mysql -u super -e 'drop user root'
F=mysql-${DB}-linux-glibc2.5-x86_64
mkdir -p ${HOME}/mysql
P=${HOME}/mysql/${F}
if [ ! -d "${P}" ]; then
wget http://cdn.mysql.com/Downloads/MySQL-${DB%.*}/${F}.tar.gz -O - | tar -zxf - --directory=${HOME}/mysql
fi
if [ -f "${P}"/my.cnf ]; then
O="--defaults-file=${P}/my.cnf"
fi
if [ -x "${P}"/scripts/mysql_install_db ]; then
I=${P}/scripts/mysql_install_db
O="--defaults-file=${P}/my.cnf"
else
I=${P}/bin/mysqld
IO=" --initialize "
O="--no-defaults "
fi
${I} ${O} ${IO} --basedir=${P} --datadir=${HOME}/db-"${DB}" --log-error=/tmp/mysql.err
PWLINE=$(grep 'A temporary password is generated for root@localhost:' /tmp/mysql.err)
PASSWD=${PWLINE##* }
if [ -x ${P}/bin/mysql_ssl_rsa_setup ]; then
${P}/bin/mysql_ssl_rsa_setup --datadir=${HOME}/db-"${DB}"
fi
# sha256 password auth keys:
openssl genrsa -out "${P}"/private_key.pem 2048
openssl rsa -in "${P}"/private_key.pem -pubout -out "${P}"/public_key.pem
${P}/bin/mysqld_safe ${O} --ledir=/ --mysqld=${P}/bin/mysqld --datadir=${HOME}/db-${DB} --socket=/tmp/mysql.sock --port 3307 --innodb-buffer-pool-size=200M --lc-messages-dir=${P}/share --plugin-dir=${P}/lib/plugin/ --log-error=/tmp/mysql.err &
while [ ! -S /tmp/mysql.sock ]; do
sleep 2
done
cat /tmp/mysql.err
if [ ! -z "${PASSWD}" ]; then
${P}/bin/mysql -S /tmp/mysql.sock -u root -p"${PASSWD}" --connect-expired-password -e "SET PASSWORD = PASSWORD('')"
fi
mysql -S /tmp/mysql.sock -u root -e "create user ${USER}@localhost; create user ${USER}@'%'; grant all on *.* to ${USER}@localhost WITH GRANT OPTION;grant all on *.* to ${USER}@'%' WITH GRANT OPTION;"
sed -e 's/3306/3307/g' -e 's:/var/run/mysqld/mysqld.sock:/tmp/mysql.sock:g' .travis.databases.json > pymysql/tests/databases.json
echo -e "[client]\nsocket = /tmp/mysql.sock\n" > "${HOME}"/.my.cnf
else
cp .travis.databases.json pymysql/tests/databases.json
fi