收藏文章 楼主

mysql 忘记root密码破解root密码破解所有用户密码,shell脚本

版块:linux   类型:普通   作者:小绿叶技术博客   查看:588   回复:0   获赞:0   时间:2021-07-26 20:32:41

#!/bin/bash

# mysql 破解重置root密码

read -p "

Hello, welcome to continuous integration eisc.cn mysql 同时破解远程和localhost数据库密码

请输入用户名:" setuser

read -p "请自定义密码:" setpasswd

mycnf="/etc/my.cnf"

NR=`cat -n $mycnf | grep "\[mysqld\]" | awk -F" " '{print $1}'` ; echo $NR

                  # 找到 [mysqld] 标签所在行

sed -i "/skip-grant-tables/d" $mycnf

                  # 删除这个root免密登录配置,重新添加

sed -i "$NR a skip-grant-tables" $mycnf ; systemctl restart mysqld mariadb

                  # 在mysqld 标签下面增加免密登录配置信息

                  # 重启数据库

echo "您输入的信息为:$setuser $setpasswd"

mysqlversion=$(mysql -uroot -peisc.cn -e "select version();" | awk -F"." 'NR==2{print $1}') ; echo "mysql版本:$mysqlversion";

if [ $mysqlversion -gt 7 ];then

      echo "当前数据库版本大于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 "低于7的版破解"

fi


                  # 登录数据库修改root密码为:eisc.cn

                  # 重点:set global read_only=0;set global read_only=1; flush privileges;set global validate_password.policy=0 ; set global validate_password.length=6;

                  # 关掉新主库的只读属性,读写属性,密码长度为6

sed -i "/skip-grant-tables/d" $mycnf; systemctl restart mysqld mariadb

                  # 删除之前的配置,重启数据


# wget eisc.cn/file/shell/mysql-passwd.sh ; sh mysql-passwd.sh

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:mysql 忘记root密码破解root密码破解所有用户密码,shell脚本

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息