aboutsummaryrefslogtreecommitdiff
path: root/lib/60-mysql
diff options
context:
space:
mode:
authorCullum Smith <cullum@sacredheartsc.com>2025-03-27 22:30:15 -0400
committerCullum Smith <cullum@sacredheartsc.com>2025-03-27 22:30:15 -0400
commit9539e58ae7653ffa5ef25cf7b18c67d705813334 (patch)
treeedae9906b601e1f51d3236e83924562f588d0cf5 /lib/60-mysql
parentd0f053485d6635d0128b815b422b421bbb836514 (diff)
downloadinfrastructure-9539e58ae7653ffa5ef25cf7b18c67d705813334.tar.gz
more mysql stuff
Diffstat (limited to 'lib/60-mysql')
-rw-r--r--lib/60-mysql25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/60-mysql b/lib/60-mysql
new file mode 100644
index 0000000..1d2f158
--- /dev/null
+++ b/lib/60-mysql
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+mysql_run(){
+ MYSQL_PWD="$boxconf_password" mysql \
+ --batch \
+ --ssl-verify-server-cert \
+ --user="$boxconf_username" \
+ "$@"
+}
+
+mysql_create_user(){
+ # $1 = mysql_host, $2 = username $3 = via
+ cat <<EOF | mysql_run --host="${1}"
+CREATE USER IF NOT EXISTS '${2}' IDENTIFIED VIA ${3};
+EOF
+}
+
+mysql_create_database(){
+ # $1 = mysql_host, $2 = dbname, $3 = owner $4 = options
+ cat <<EOF | mysql_run --host="${1}"
+CREATE DATABASE IF NOT EXISTS ${2} ${4:-};
+GRANT ALL PRIVILEGES ON ${2}.* TO '${3}';
+FLUSH PRIVILEGES;
+EOF
+}