From ee1e699060a1cdaefffe7c69995a35183b37b086 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Feb 2024 13:42:24 -0500 Subject: ensure replication user is created on server with output to user --- src/mariadb-push-replica.sh | 66 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/src/mariadb-push-replica.sh b/src/mariadb-push-replica.sh index 140fb2e..cde164c 100755 --- a/src/mariadb-push-replica.sh +++ b/src/mariadb-push-replica.sh @@ -56,8 +56,7 @@ run_() { case "$1" in primary_host | replica_host ) ;; - *_host ) return 54 ;; # lol wut - * ) return 53 ;; + * ) return 58 ;; esac (set -x : ${1%_host} : $2 $3 ${4:+ ...}) @@ -151,7 +150,7 @@ to . } -create_replication_user() +create_and_authorize_replication_user() { mariadb --skip-reconnect -t <<. create or replace @@ -161,12 +160,28 @@ identified by '$3' ; -grant replication slave +grant + replication replica on *.* to '$2'@'$1' ; +select + @@hostname + as + 'primary host' +, concat (user, '@', host) + as + login +, repl_slave_priv + as + 'replica privilege' +from + mysql.user +where + repl_slave_priv = 'Y' +; . } @@ -224,9 +239,11 @@ set_server_id() set -e chosen_id=$(truncated_machineid_decimal_string_int32) [ "$chosen_id" -gt 1 ] - mariadb -v --skip-reconnect -t <&2 + mariadb -t --skip-reconnect <<. select master_gtid_wait('$gtid') as \`primary_gtid_wait('$gtid')\` @@ -479,7 +513,7 @@ cleanup_after_test() show_all_databases() { -mariadb -t "$@" <<. +mariadb --skip-reconnect -t "$@" <<. select @@hostname , @@server_id -- cgit v1.2.3