#!/bin/bash echo "* Resetting mysql root password..." svcstop /service/mysql || exit 1 PASSWD=`cat /proc/sys/kernel/random/uuid` || exit 1 echo "$PASSWD" > /etc/my.passwd #make sure those permissions are safe: chown root /etc/my.passwd chmod 700 /etc/my.passwd #also create mysql option file echo " ### automaticly created by syn3-mysqlfix [client] host=localhost user=root password=$PASSWD" > /root/.my.cnf chmod 700 /root/.my.cnf #start mysql with the ini file: echo "GRANT ALL ON *.* TO 'root'@'localhost' identified by '$PASSWD' WITH GRANT OPTION;" > /etc/my.init svcstart /service/mysql #dont exit, always delete ini file! sleep 1 rm /etc/my.init #secure database by deleting anoynmous logins and passwordless logins: mysql --execute="DELETE FROM mysql.user WHERE User='';" mysql &>/dev/null mysql --execute="DELETE FROM mysql.user WHERE Password='';" mysql &>/dev/null mysql --execute="flush privileges;" mysql &>/dev/null svcreset /service/mysql || exit 1 echo "Mysql rootpassword resetted, stored in /etc/my.passwd and created option file for root. " exit 0