#!/bin/bash#```ops#title:Linux MYSQL 密码重置脚本#descr:#```PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
exportPATH# Check if user is rootif[$(id-u)!="0"];thenprintf"Error: You must be root to run this script!\n"exit1fimysql_root_password="$RANDOM***$RANDOM"
/etc/init.d/mysqld stop
/usr/local/mysql-5.1.66/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1&sleep10
/usr/local/mysql-5.1.66/bin/mysql -u root mysql <<EOF
update user set password = Password('$mysql_root_password') where User = 'root';
EOFreset_status=`echo $?`if[$reset_status="0"];thenkillall mysqld
sleep10
/etc/init.d/mysqld start
echo$mysql_root_password> /tmp/mysql.txt
elseprintf"failed!\n"firm-rf$0