Skip to content

Instantly share code, notes, and snippets.

@hightemp
Last active August 29, 2015 13:57
Show Gist options
  • Save hightemp/9708517 to your computer and use it in GitHub Desktop.
Save hightemp/9708517 to your computer and use it in GitHub Desktop.
#!/bin/bash
while [ `whoami` != 'root' ]; do
su -
done
USER="-u root"
mysql_config $USER
mysql_install_db $USER
echo "Enter password for root (press <enter> for genenerate automaticaly):"
read PASSWORD
if [ '' == $PASSWORD ]; then
LEN=0
while [ $LEN -lt 10 ]; do
R=$((RANDOM % 3))
case "$R" in
"0") N=$(((RANDOM % 10)+48));; # 48-57
"1") N=$(((RANDOM % 26)+65));; # 65-90
"2") N=$(((RANDOM % 26)+97));; # 97-122
esac
C=`printf "%x" $N`
PASSWORD=$PASSWORD`printf "\x$C"`
LEN=${#PASSWORD}
done
fi
echo "password: $PASSWORD"
mysqladmin $USER password '$PASSWORD'
mysqld_safe $USER &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment