summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@vps-18a7a2b7.vps.ovh.ca>2024-02-15 16:20:39 -0500
committerroot <root@vps-18a7a2b7.vps.ovh.ca>2024-02-15 16:23:50 -0500
commit254c699347896f1faa49e1254d3fa31ae22cafd8 (patch)
tree9162591ef2335780baf1b287f7b3051f5f50ffb8
parentd21659f025afef4c55f74b87869fc33564342c78 (diff)
mariadb scripts
-rwxr-xr-xmariadb/drop-all-mariadb-databases65
-rwxr-xr-xmariadb/mariadb-list-databases12
-rwxr-xr-xmariadb/mariadb-show-users13
3 files changed, 90 insertions, 0 deletions
diff --git a/mariadb/drop-all-mariadb-databases b/mariadb/drop-all-mariadb-databases
new file mode 100755
index 0000000..71d83fe
--- /dev/null
+++ b/mariadb/drop-all-mariadb-databases
@@ -0,0 +1,65 @@
1#!/bin/bash
2set -e
3set -o pipefail
4
5never_drop=(
6 information_schema
7 mysql
8 performance_schema
9 sys
10)
11
12never_drop()
13{
14 grep -vF ${never_drop[@]/#/ -e }
15}
16
17choose_drops()
18{
19 mariadb -ss -b <<< 'show databases' |
20 never_drop
21}
22
23execute_drops()
24{
25 while read dbname
26 do
27 t=\`
28 printf 'drop database %s ;\n' \
29 "$t${dbname//$t/$t$t}$t"
30 done |
31 if [ "$REALLY_DROP_ALL_MARIADB_DATABASES" ]
32 then
33 mariadb -v
34 else
35 cat
36 fi
37}
38
39warn()
40{
41 printf 'Warning: %s\n' "$*" >&2
42}
43
44perr()
45{
46 printf 'Error: %s: %s\n' "$0" "$*" >&2
47}
48
49case "$#$1" in
50 1--drop-all-databases )
51 shift
52 REALLY_DROP_ALL_MARIADB_DATABASES=y
53 ;;
54 0 )
55 warn 'No databases will be dropped'
56 warn 'To execute the SQL, supply' \
57 'command-line argument: --drop-all-databases'
58 ;;
59 * )
60 perr "Unexpected argument list: ${@@Q}"
61 exit 1
62 ;;
63esac
64
65choose_drops | execute_drops
diff --git a/mariadb/mariadb-list-databases b/mariadb/mariadb-list-databases
new file mode 100755
index 0000000..527ec90
--- /dev/null
+++ b/mariadb/mariadb-list-databases
@@ -0,0 +1,12 @@
1#!/bin/bash
2mariadb -t "$@" <<.
3select
4 @@hostname
5, @@server_id
6, schema_name
7as
8 'database'
9from
10 information_schema.schemata
11;
12.
diff --git a/mariadb/mariadb-show-users b/mariadb/mariadb-show-users
new file mode 100755
index 0000000..1cbd074
--- /dev/null
+++ b/mariadb/mariadb-show-users
@@ -0,0 +1,13 @@
1#!/bin/bash
2mariadb <<.
3select
4 concat (host, '@', user)
5 as
6 user
7, json_detailed (priv)
8 as
9 priv
10from
11 mysql.global_priv
12\G
13.