forked from tutumcloud/mariadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_mariadb_admin_user.sh
36 lines (28 loc) · 1.11 KB
/
create_mariadb_admin_user.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
/usr/bin/mysqld_safe > /dev/null 2>&1 &
RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MariaDB service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done
PASS=${MARIADB_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${MARIADB_PASS} ] && echo "preset" || echo "random" )
echo "=> Creating MariaDB admin user with ${_word} password"
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
echo "=> Done!"
echo "========================================================================"
echo "You can now connect to this MariaDB Server using:"
echo ""
if [ $MARIADB_PASS ]; then
echo " mysql -uadmin -p<MARIADB_PASS> -h$(hostname -I) -P<port>"
else
echo " mysql -uadmin -p$PASS -h$(hostname -I) -P<port>"
fi
echo ""
echo "Please remember to change the above password as soon as possible!"
echo "MariaDB user 'root' has no password but only allows local connections"
echo "========================================================================"
mysqladmin -uroot shutdown