資源簡(jiǎn)介
mysql root用戶誤刪除一鍵恢復(fù),使用python 腳本一鍵恢復(fù)
代碼片段和文件信息
import?pymysql
import?os
#修改配置文件獲取權(quán)限
print(“modify?my.cnf?skip?grant?tables.........“)
os.system(“echo‘-skip-grant-tables‘>>/etc/my.cnf“)
k?=?os.system(“systemctl?restart?mysqld“)
if?k==0:
????pint(“erro:“k)
else:
????print(“modify?success!“)
????#連接數(shù)據(jù)庫(kù)
????db=pymysql.connect(“127.0.0.1“)
????cursor=db.cursor()
????cursor.execute(“use?mysql“)
????#添加root用戶并更新root權(quán)限
????SQL_SYN=“insert?into?user(Userauthentication_stringssl_cipher?x509_issuer?x509_subject)?values(‘root‘‘‘‘‘‘‘‘‘)“
????cursor.execute(SQL_SYN)
????SQL_SYN=“update?user?set?Host=‘%‘select_priv=‘y‘?insert_priv=‘y‘update_priv=‘y‘Alter_priv=‘y‘delete_priv=‘y‘create_priv=‘y‘drop_priv=‘y‘reload_priv=‘y‘shutdown_priv=‘y‘Process_priv=‘y‘file_priv=‘y‘grant_priv=‘y‘References_priv=‘y‘index_priv=‘y‘create_user_priv=‘y‘show_db_priv=‘y‘super_priv=‘y‘create_tmp_table_priv=‘y‘Lock_tables_priv=‘
評(píng)論
共有 條評(píng)論