Bob Mottram 7 年之前
父節點
當前提交
45be6e2915
共有 1 個檔案被更改,包括 22 行新增13 行删除
  1. 22
    13
      src/freedombone-utils-database

+ 22
- 13
src/freedombone-utils-database 查看文件

144
     fi
144
     fi
145
 }
145
 }
146
 
146
 
147
+function mariadb_fix_authentication {
148
+    # See http://www.pontikis.net/blog/debian-9-stretch-rc3-web-server-setup-php7-mariadb
149
+    # https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin
150
+    function_check run_query
151
+    run_query_root mysql "update mysql.user set plugin = '' where User='root'; flush privileges;"
152
+    run_query_root mysql "UPDATE user SET Password=PASSWORD('$MARIADB_PASSWORD') where USER='root'; flush privileges;"
153
+
154
+    sed -i 's| --skip-grant-tables||g' /lib/systemd/system/mariadb.service
155
+    systemctl daemon-reload
156
+    systemctl restart mariadb
157
+}
158
+
159
+function mariadb_create_root_user {
160
+    run_query mysql "CREATE USER 'root@localhost' IDENTIFIED BY '${MARIADB_PASSWORD}'; flush privileges;"
161
+    run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
162
+    run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
163
+}
164
+
147
 function install_mariadb {
165
 function install_mariadb {
148
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
166
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
149
         return
167
         return
151
     apt-get -yq install software-properties-common debconf-utils
169
     apt-get -yq install software-properties-common debconf-utils
152
     apt-get -yq update
170
     apt-get -yq update
153
 
171
 
172
+    remove_watchdog_daemon mariadb
173
+
154
     function_check get_mariadb_password
174
     function_check get_mariadb_password
155
     get_mariadb_password
175
     get_mariadb_password
156
     if [ ! $MARIADB_PASSWORD ]; then
176
     if [ ! $MARIADB_PASSWORD ]; then
185
     systemctl daemon-reload
205
     systemctl daemon-reload
186
     systemctl restart mariadb
206
     systemctl restart mariadb
187
 
207
 
188
-    # See http://www.pontikis.net/blog/debian-9-stretch-rc3-web-server-setup-php7-mariadb
189
-    # https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin
190
-
191
-    function_check run_query
192
-    run_query_root mysql "update mysql.user set plugin = '' where User='root'; flush privileges;"
193
-    run_query_root mysql "UPDATE user SET Password=PASSWORD('$MARIADB_PASSWORD') where USER='root'; flush privileges;"
194
-
195
-    sed -i 's| --skip-grant-tables||g' /lib/systemd/system/mariadb.service
196
-    systemctl daemon-reload
197
-    systemctl restart mariadb
208
+    mariadb_fix_authentication
198
 
209
 
199
     # mariadb daemon seems to occasionally crash
210
     # mariadb daemon seems to occasionally crash
200
     # This is a crude attempt to keep it running
211
     # This is a crude attempt to keep it running
201
     add_watchdog_daemon mariadb
212
     add_watchdog_daemon mariadb
202
 
213
 
203
-    run_query mysql "CREATE USER 'root@localhost' IDENTIFIED BY '${MARIADB_PASSWORD}'; flush privileges;"
204
-    run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
205
-    run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
214
+    mariadb_create_root_user
206
 
215
 
207
     mark_completed $FUNCNAME
216
     mark_completed $FUNCNAME
208
 }
217
 }