Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql to view the user's permissions script

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Install mysql support python package

yum -y install mysql-connector-python

Python scripts for viewing MySQL user permissions

vi py_priv.py

#!/ usr/bin/env python

#coding:utf8

#epel source &yum -y install mysql-connector-python

from __future__ import print_function

import re,sys

import mysql.connector as mdb

config = {

'user':'root',

'password':'123456',

'host':'192.168.1.191',

'port':3306,

'database':'mysql'

}

def GetPriv():

show_username="select concat(\"'\",user,\"'\",'@',\"'\",host,\"'\"),password from mysql.user"

cursor.execute(show_username)

users={}

for i in cursor:

username=i[0]

password=i[1]

users[username]=password

for key in users:

try:

show_priv='show grants for %s' % key

cursor.execute(show_priv)

priv=[]

for i in cursor:

priv.append(tuple(re.split(r' TO ',str(*i))[0].split(r' ON ')))

print(''.center(80,'~'))

print('{0:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report