mariadb-create-superuser/mysql-create-superuser.sh

28 lines
585 B
Bash
Raw Permalink Normal View History

2022-02-22 23:41:47 +02:00
#!/usr/bin/env bash
PWGEN=`which pwgen`
if [ -z "${PWGEN}" ];
then
echo "Could not finf \"pwgen\" binary"
exit 1
fi
AUTOGEN_PASSWORD=`pwgen -n1 -v 40`
USERNAME="$1"
if [ -z "${USERNAME}" ];
then
echo "Missing username"
exit 1
fi
cat <<EOF
CREATE USER '${USERNAME}'@'localhost' IDENTIFIED BY '${AUTOGEN_PASSWORD}';
GRANT ALL PRIVILEGES ON *.* TO '${USERNAME}'@'localhost' WITH GRANT OPTION;
CREATE USER '${USERNAME}'@'%' IDENTIFIED BY '${AUTOGEN_PASSWORD}';
GRANT ALL PRIVILEGES ON *.* TO '${USERNAME}'@'%' WITH GRANT OPTION;
SHOW GRANTS FOR ${USERNAME};
FLUSH PRIVILEGES;
EOF