eole-mariadb/scripts/mariadbPwd

28 lines
565 B
Plaintext
Raw Normal View History

#!/bin/bash
#
# Renew MariaDB root password
# Just like old (mysql_pwd.py)
#
cmd="mysql"
options='--defaults-file=/etc/mysql/debian.cnf'
2018-04-12 17:16:59 +02:00
role=$(CreoleGet dbClusterPosition 'Leader')
2018-04-12 17:10:39 +02:00
2018-04-12 17:14:05 +02:00
if [[ ${role} == "Leader" ]]
then
2018-04-12 17:10:39 +02:00
if [[ -z ${1} ]]
then
read -s -p "New Password : " password
echo
else
password="${1}"
fi
2018-04-12 17:10:39 +02:00
sql="FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY '${password}';"
2018-04-12 17:10:39 +02:00
${cmd} ${options} -e "${sql}"
exit $?
else
echo "This command don't work in a MariaDB Cluster Node, try in the Leader"
exit 3
fi