MySQL forgets root password cracking root password cracking all user passwords, shell script

eisc 2022-06-24 06:03:02 阅读数:274

mysqlforgetsrootpasswordcracking
#!/bin/bash
# mysql Crack reset root password
read -p "
Hello, welcome to continuous integration eisc.cn mysql Crack both remote and localhost Database password
Please enter a user name :" setuser
read -p " Please customize your password :" setpasswd
mycnf="/etc/my.cnf"
NR=`cat -n $mycnf | grep "\[mysqld\]" | awk -F" " '{print $1}'` ; echo $NR
# find [mysqld] The line of the tag
sed -i "/skip-grant-tables/d" $mycnf
# Delete this root Password free login configuration , To add
sed -i "$NR a skip-grant-tables" $mycnf ; systemctl restart mysqld mariadb
# stay mysqld Add password free login configuration information under the label
# Restart the database
echo " The information you entered is :$setuser $setpasswd"
mysqlversion=$(mysql -uroot -peisc.cn -e "select version();" | awk -F"." 'NR==2{print $1}') ; echo "mysql edition :$mysqlversion";
if [ $mysqlversion -gt 7 ];then
echo " The current database version is greater than 7"
mysql -e "use mysql;select user,authentication_string from user; set global read_only=0;set global read_only=1; set global validate_password.policy=0 ; set global validate_password.length=6;flush privileges;alter user '$setuser'@'localhost' identified by '$setpasswd';alter user '$setuser'@'%' identified by '$setpasswd';"
else
mysql -e "use mysql;select user,authentication_string from user; set global read_only=0;set global read_only=1; use mysql;select user,authentication_string from user; set global read_only=0;set global read_only=1; UPDATE user SET password=password('$setpasswd') WHERE user='$setuser';"
echo " lower than 7 Version cracking of "
fi
# Log in to the database to modify root The password for :eisc.cn
# a key :set global read_only=0;set global read_only=1; flush privileges;set global validate_password.policy=0 ; set global validate_password.length=6;
# Turn off the read-only property of the new master library , Read write properties , The length of the password is 6
sed -i "/skip-grant-tables/d" $mycnf; systemctl restart mysqld mariadb
# Delete the previous configuration , Restart the data
# wget eisc.cn/file/shell/mysql-passwd.sh ; sh mysql-passwd.sh
copyright:author[eisc],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/20210727185929831l.html