Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql to view the user's permissions script

Shulou Source: shulou.com Published: 2022-06-01 06:58:13 12月03日 Update

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:

Tags: Permissions users passwords usernames scripts results support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Redmi Shulou Tech Info Huawei