Skip to content

Commit 75afa19

Browse files
committed
Initial commit
1 parent 38ccc3b commit 75afa19

File tree

3 files changed

+4179
-1
lines changed

3 files changed

+4179
-1
lines changed

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# mysql-sample-db
2-
Sample MySQL and MariaDB database data that can be used for upgrade testing
2+
3+
Sample MySQL and MariaDB database data that can be used for upgrade testing.
4+
5+
Database structure and data are taken from [mysqltutorial.org](http://www.mysqltutorial.org/mysql-sample-database.aspx) and the database is initialized with the `mysqld` daemon of particular version. The initialized data of a particular version are kept in corresponding branch.
6+
7+
We have (or plan to have) the following versions available in corresponding branches:
8+
9+
* [MySQL 5.1](@mysql-5.0)
10+
* [MySQL 5.1](@mysql-5.1)
11+
* [MySQL 5.1](@mysql-5.5)
12+
* [MySQL 5.1](@mysql-5.6)
13+
* [MySQL 5.1](@mysql-5.7)
14+
* [MySQL 5.1](@mariadb-5.3)
15+
* [MySQL 5.1](@mariadb-5.5)
16+
* [MySQL 5.1](@mariadb-10.0)
17+
* [MySQL 5.1](@mariadb-10.1)
18+
* [MySQL 5.1](@mariadb-10.2)
19+
20+
Such data can be used for various tasks, for example testing upgrade.
21+
22+
Generation of the data can be done using `./mysql-sample-db generate` and the data are stored into `./data`.
23+
24+
Validity of the data can be checked using `./mysql-sample-db check` script.
25+

mysql-sample-db

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
THIS_DIR=$(dirname ${BASH_SOURCE[0]})
4+
MYSQLD_BIN=/usr/libexec/mysqld
5+
OUTPUT_DIR=${THIS_DIR}/data
6+
PID_FILE=/tmp/mysql.pid
7+
SOCKET_FILE=/tmp/mysql.sock
8+
LOG_FILE=/tmp/mysql.log
9+
DUMP_FILE=mysqlsampledatabase.sql
10+
11+
action=${1}
12+
13+
set -e
14+
15+
rm -f ${LOG_FILE}
16+
touch ${LOG_FILE}
17+
18+
usage() {
19+
echo "Tool for generating and checking of MySQL/MariaDB data dir"
20+
echo
21+
echo "Usage: `basename $0` <action>"
22+
echo
23+
echo "Available actions:"
24+
echo " generate Download and generate data, store them to ./data directory"
25+
echo " check Check data in ./data directory with mysqlcheck"
26+
exit 1
27+
}
28+
29+
wait_for_mysql() {
30+
while true; do
31+
echo "Waiting for MySQL server to accept connections ..."
32+
mysqladmin --socket=${SOCKET_FILE} ping &>/dev/null && echo "MySQL server is ready" && return 0
33+
sleep 1
34+
done
35+
}
36+
37+
download_dump() {
38+
echo "Downloading and unpacking data ..."
39+
wget -O mysqldata.zip http://www.mysqltutorial.org/download/2
40+
rm -rf ${PID_FILE} ${SOCKET_FILE} ${OUTPUT_DIR} ${DUMP_FILE}
41+
unzip mysqldata.zip
42+
}
43+
44+
init_data() {
45+
echo "Initializing data ..."
46+
/usr/bin/mysql_install_db --rpm --datadir=${OUTPUT_DIR} &>>${LOG_FILE}
47+
}
48+
49+
start_local_server() {
50+
echo "Running the server ..."
51+
/usr/libexec/mysqld --datadir=${OUTPUT_DIR} --skip-networking --socket=${SOCKET_FILE} --pid-file=${PID_FILE} &>>${LOG_FILE} &
52+
wait_for_mysql
53+
}
54+
55+
load_data() {
56+
echo "Creating data ..."
57+
mysql --user root --socket=${SOCKET_FILE} <${DUMP_FILE}
58+
}
59+
60+
check_data() {
61+
echo "Checking data ..."
62+
mysqlcheck --user root --socket=${SOCKET_FILE} --all-databases
63+
}
64+
65+
stop_server() {
66+
echo "Killing the server ..."
67+
kill $(cat ${PID_FILE})
68+
}
69+
70+
action_generate() {
71+
download_dump
72+
init_data
73+
start_local_server
74+
load_data
75+
check_data
76+
stop_server
77+
}
78+
79+
action_check() {
80+
start_local_server
81+
check_data
82+
stop_server
83+
}
84+
85+
case ${action} in
86+
generate) action_generate ;;
87+
check) action_check ;;
88+
*) usage ;;
89+
esac
90+

0 commit comments

Comments
 (0)