2
2
3
3
set -eux
4
4
5
- CHANGED_PWD=false
6
- # Change the password recreating the root user on mariadb < 10.2
5
+ # Change the password to be empty.
6
+ CHANGED_PASSWORD=false
7
+ # Change the password to be empty, recreating the root user on mariadb < 10.2
7
8
# where ALTER USER is not available.
8
9
# https://stackoverflow.com/questions/56052177/
9
- CHANGED_PWD_BY_RECREATE =false
10
+ CHANGED_PASSWORD_BY_RECREATE =false
10
11
11
12
# Install the default used DB if DB is not set.
12
- if [[ -n ${GITHUB_ACTION -} && -z ${DB-} ]]; then
13
+ if [[ -n ${GITHUB_ACTIONS -} && -z ${DB-} ]]; then
13
14
if command -v lsb_release > /dev/null; then
14
15
case " $( lsb_release -cs) " in
15
16
xenial | bionic)
16
17
sudo apt-get install -qq mysql-server-5.7 mysql-client-core-5.7 mysql-client-5.7
17
- CHANGED_PWD =true
18
+ CHANGED_PASSWORD =true
18
19
;;
19
20
focal)
20
21
sudo apt-get install -qq mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
21
- CHANGED_PWD =true
22
+ CHANGED_PASSWORD =true
22
23
;;
23
24
* )
24
25
;;
34
35
# Install MySQL 5.7 if DB=mysql57
35
36
if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then
36
37
sudo bash .travis_mysql57.sh
37
- CHANGED_PWD =true
38
+ CHANGED_PASSWORD =true
38
39
fi
39
40
40
41
# Install MySQL 8.0 if DB=mysql80
41
42
if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then
42
43
sudo bash .travis_mysql80.sh
43
- CHANGED_PWD =true
44
+ CHANGED_PASSWORD =true
44
45
fi
45
46
46
47
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
47
48
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.0 ]]; then
48
- if [[ -n ${GITHUB_ACTION -} ]]; then
49
+ if [[ -n ${GITHUB_ACTIONS -} ]]; then
49
50
sudo apt-get install -y -o Dpkg::Options::=' --force-confnew' mariadb-server mariadb-server-10.0 libmariadb2
50
- CHANGED_PWD_BY_RECREATE =true
51
+ CHANGED_PASSWORD_BY_RECREATE =true
51
52
else
52
53
sudo apt-get install -y -o Dpkg::Options::=' --force-confnew' libmariadbclient-dev
53
54
fi
54
55
fi
55
56
56
57
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
57
58
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.1 ]]; then
58
- if [[ -n ${GITHUB_ACTION -} ]]; then
59
+ if [[ -n ${GITHUB_ACTIONS -} ]]; then
59
60
sudo apt-get install -y -o Dpkg::Options::=' --force-confnew' mariadb-server mariadb-server-10.1 libmariadb-dev
60
- CHANGED_PWD_BY_RECREATE =true
61
+ CHANGED_PASSWORD_BY_RECREATE =true
61
62
else
62
63
sudo apt-get install -y -o Dpkg::Options::=' --force-confnew' libmariadbclient-dev
63
64
fi
@@ -70,16 +71,29 @@ if [[ -n ${DB-} && x$DB =~ ^xmariadb10.2 ]]; then
70
71
fi
71
72
72
73
# Install MariaDB 10.3 if DB=mariadb10.3
73
- if [[ -n ${GITHUB_ACTION -} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
74
+ if [[ -n ${GITHUB_ACTIONS -} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
74
75
sudo apt-get install -y -o Dpkg::Options::=' --force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev
75
- CHANGED_PWD =true
76
+ CHANGED_PASSWORD =true
76
77
fi
77
78
78
- # Install MySQL if OS=darwin
79
+ # Install MySQL/MariaDB if OS=darwin
79
80
if [[ x$OSTYPE =~ ^xdarwin ]]; then
80
- brew update
81
- brew install " $DB " mariadb-connector-c
82
- $( brew --prefix " $DB " ) /bin/mysql.server start
81
+ brew update > /dev/null
82
+
83
+ # Check available packages.
84
+ for KEYWORD in mysql mariadb; do
85
+ brew search " ${KEYWORD} "
86
+ done
87
+
88
+ brew info " $DB "
89
+ brew install " $DB "
90
+ DB_PREFIX=" $( brew --prefix " ${DB} " ) "
91
+ export PATH=" ${DB_PREFIX} /bin:${PATH} "
92
+ export LDFLAGS=" -L${DB_PREFIX} /lib"
93
+ export CPPFLAGS=" -I${DB_PREFIX} /include"
94
+
95
+ mysql.server start
96
+ CHANGED_PASSWORD_BY_RECREATE=true
83
97
fi
84
98
85
99
# TODO: get SSL working on OS X in Travis
@@ -88,14 +102,12 @@ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
88
102
sudo service mysql restart
89
103
fi
90
104
91
- # Print the MySQL version and create the test DB
92
- if [[ x$OSTYPE =~ ^xdarwin ]]; then
93
- $( brew --prefix " $DB " ) /bin/mysqld --version
94
- $( brew --prefix " $DB " ) /bin/mysql -u root -e ' CREATE DATABASE IF NOT EXISTS test'
95
- else
96
- mysqld --version
105
+ mysqld --version
97
106
98
- if [[ -n ${GITHUB_ACTION-} && -f /etc/mysql/debian.cnf ]]; then
107
+ MYSQL_OPTS=' '
108
+ DB_SYS_USER=root
109
+ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
110
+ if [[ -n ${GITHUB_ACTIONS-} && -f /etc/mysql/debian.cnf ]]; then
99
111
MYSQL_OPTS=' --defaults-extra-file=/etc/mysql/debian.cnf'
100
112
# Install from packages in OS official packages.
101
113
if sudo grep -q debian-sys-maint /etc/mysql/debian.cnf; then
@@ -105,25 +117,20 @@ else
105
117
# xenial
106
118
DB_SYS_USER=root
107
119
fi
108
- else
109
- # Install from official mysql packages.
110
- MYSQL_OPTS=' '
111
- DB_SYS_USER=root
112
120
fi
121
+ fi
113
122
114
- if [ " ${CHANGED_PWD } " = true ]; then
115
- # https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
116
- sudo mysql ${MYSQL_OPTS} -u " ${DB_SYS_USER} " \
117
- -e " ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
118
- elif [ " ${CHANGED_PWD_BY_RECREATE } " = true ]; then
119
- sudo mysql ${MYSQL_OPTS} -u " ${DB_SYS_USER} " << SQL
123
+ if [ " ${CHANGED_PASSWORD } " = true ]; then
124
+ # https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
125
+ sudo mysql ${MYSQL_OPTS} -u " ${DB_SYS_USER} " \
126
+ -e " ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
127
+ elif [ " ${CHANGED_PASSWORD_BY_RECREATE } " = true ]; then
128
+ sudo mysql ${MYSQL_OPTS} -u " ${DB_SYS_USER} " << SQL
120
129
DROP USER 'root'@'localhost';
121
130
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
122
131
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
123
132
FLUSH PRIVILEGES;
124
133
SQL
125
- fi
126
-
127
- # IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
128
- mysql -u root -e ' CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
129
134
fi
135
+
136
+ mysql -u root -e ' CREATE DATABASE IF NOT EXISTS test'
0 commit comments