GithubHelp home page GithubHelp logo

nestordeharo / python-mysql-access-privilege Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 182 KB

Python function generates MySQL command for whitelist I.P. adress, users and grant permission

License: MIT License

Python 100.00%

python-mysql-access-privilege's Introduction

Python MySQL Simple Account Management Generator

Description:

This is a simple script in Python that help you to generate MySQL commands for whitelist I.P. addresses, create user with passwords and grant permissions to tables and database.

At the end of this script, you just copy paste the output and integrate into MySQL shell.

Support Version

Python 2.x.x

Usage

The function inside the main.py: Db_User_Privileges needs three different variables:

  1. A List of the n different i.p. addresses we want to whitelist
  ip_list = ['I.P.address1', 'I.P.address2', ... ]
  1. A dictionary of users and password we are going to introduce in our MySQL server
  user_password_dict = {'user_1':'strong_password', 'user_2': 'strong_password2', ...}
  1. A dictionary of databases, tables and permissions we assign for each case

Note: Use "*" for assign all tables inside the database

  db_table_privilege = {
    'db_1':{
      '*': ['SELECT', 'INSERT']
    }, 
    'db_2':{
      'table_1':['SELECT'], 
      'table_2': ['SELECT','INSERT']
    },
    ...
  }

Then we need to call the Db_User_Privileges function and the script will print the commands you could introduce in the MySQL shell

  result = Db_User_Privileges(ip_list, user_password_dict, db_table_privilege)

Result

Just copy & paste the result and ready to integrate in MySQL shell.

  CREATE USER 'user'@'ip_add_1' IDENTIFIED BY 'secret_password';  GRANT ALL PRIVILEGES ON db_2.table_2 TO 'user'@'ip_add_1'; GRANT SELECT, INSERT ON db_2.table_1 TO 'user'@'ip_add_1'; GRANT ALL PRIVILEGES ON db_1.* TO 'user'@'ip_add_1';CREATE USER 'user'@'ip_add_2' IDENTIFIED BY 'secret_password';  GRANT ALL PRIVILEGES ON db_2.table_2 TO 'user'@'ip_add_2'; GRANT SELECT, INSERT ON db_2.table_1 TO 'user'@'ip_add_2'; GRANT ALL PRIVILEGES ON db_1.* TO 'user'@'ip_add_2'; FLUSH PRIVILEGES;

Note: Spaces between commands has been eliminated to diminish problems when execute by MySQL shell

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.