Ver código fonte

Don't use mysqladmin

Bob Mottram 7 anos atrás
pai
commit
a5fe0462de
1 arquivos alterados com 32 adições e 24 exclusões
  1. 32
    24
      src/freedombone-utils-database

+ 32
- 24
src/freedombone-utils-database Ver arquivo

181
     run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
181
     run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
182
     run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
182
     run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
183
 
183
 
184
-    mysqladmin -u root password "$MARIADB_PASSWORD"
185
     mark_completed $FUNCNAME
184
     mark_completed $FUNCNAME
186
 }
185
 }
187
 
186
 
259
     shred -zu $INSTALL_DIR/batch.sql
258
     shred -zu $INSTALL_DIR/batch.sql
260
 }
259
 }
261
 
260
 
262
-function create_database {
263
-    app_name="$1"
264
-    app_admin_password="$2"
265
-    app_admin_username=$3
266
-    if [ ! -d $INSTALL_DIR ]; then
267
-        mkdir $INSTALL_DIR
268
-    fi
269
-    if [ ! $app_admin_username ]; then
270
-        app_admin_username=${app_name}admin
271
-    fi
272
-    echo "create database ${app_name};
273
-CREATE USER '$app_admin_username@localhost' IDENTIFIED BY '${app_admin_password}';
274
-update mysql.user set plugin = '' where User='$app_admin_username@localhost';
275
-GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
276
-flush privileges;
277
-quit" > $INSTALL_DIR/batch.sql
278
-    chmod 600 $INSTALL_DIR/batch.sql
279
-    mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
280
-    shred -zu $INSTALL_DIR/batch.sql
281
-}
282
-
283
 function initialise_database {
261
 function initialise_database {
284
     database_name=$1
262
     database_name=$1
285
     database_file=$2
263
     database_file=$2
301
     mysql -e "$database_query" $database_name
279
     mysql -e "$database_query" $database_name
302
 }
280
 }
303
 
281
 
282
+function create_database {
283
+    app_name="$1"
284
+    app_admin_password="$2"
285
+    app_admin_username=$3
286
+    if [ ! -d $INSTALL_DIR ]; then
287
+        mkdir $INSTALL_DIR
288
+    fi
289
+    if [ ! $app_admin_username ]; then
290
+        app_admin_username=${app_name}admin
291
+    fi
292
+
293
+    echo "create database ${app_name};
294
+CREATE USER '$app_admin_username@localhost' IDENTIFIED BY '${app_admin_password}';
295
+update mysql.user set plugin = '' where User='$app_admin_username@localhost';
296
+GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
297
+flush privileges;
298
+quit" > $INSTALL_DIR/batch.sql
299
+    chmod 600 $INSTALL_DIR/batch.sql
300
+    mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
301
+    shred -zu $INSTALL_DIR/batch.sql
302
+}
303
+
304
 function run_query_with_output {
304
 function run_query_with_output {
305
     database_name=$1
305
     database_name=$1
306
     database_query=$2
306
     database_query=$2
313
 }
313
 }
314
 
314
 
315
 function drop_database {
315
 function drop_database {
316
-    database_name=$1
316
+    database_name="$1"
317
+
317
     get_mariadb_password
318
     get_mariadb_password
318
-    mysqladmin -uroot -p"$MARIADB_PASSWORD" -f drop $database_name
319
+
320
+    echo "drop database ${app_name};
321
+flush privileges;
322
+quit" > $INSTALL_DIR/batch.sql
323
+    chmod 600 $INSTALL_DIR/batch.sql
324
+    mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
325
+    shred -zu $INSTALL_DIR/batch.sql
319
 }
326
 }
320
 
327
 
328
+
321
 function database_reinstall {
329
 function database_reinstall {
322
     apt-get -yq purge mariadb*
330
     apt-get -yq purge mariadb*
323
     rm -rf /var/lib/mysql
331
     rm -rf /var/lib/mysql