資源簡介
mysql root用戶誤刪除一鍵恢復,使用python 腳本一鍵恢復
代碼片段和文件信息
import?pymysql
import?os
#修改配置文件獲取權限
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!“)
????#連接數據庫
????db=pymysql.connect(“127.0.0.1“)
????cursor=db.cursor()
????cursor.execute(“use?mysql“)
????#添加root用戶并更新root權限
????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=‘
- 上一篇:python電子鋼琴簡易版
- 下一篇:python爬取17k的小說.py
評論
共有 條評論