aboutsummaryrefslogtreecommitdiff
path: root/lib/60-mysql
diff options
context:
space:
mode:
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
+}