This commit is contained in:
root 2022-02-22 23:41:47 +02:00
commit e509155207
2 changed files with 29 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
* <https://tableplus.com/blog/2018/10/how-to-create-a-superuser-in-mysql.html>

27
mysql-create-superuser.sh Executable file
View File

@ -0,0 +1,27 @@
#!/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