zoukankan      html  css  js  c++  java
  • 创建MySQL账户

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    #----------------------------------------------------------#
    # Date    : xxxx-xx-xx                                     #
    # Author  : Created by zhouwanchun.                        #
    # Wechat  : lovemysql3306                                  #
    # Function: This scripts function is ...                   #
    # Version : 1.1                                            #
    #----------------------------------------------------------#
    
    # 导入模块
    import os
    import subprocess
    import mysql.connector
    import myloginpath
    
    # Linux终端清屏
    os.system('clear')
    
    # 注释信息
    print("""33[1;36m
    ############################################################
    # Date    : 2020-05-22                                     #
    # Author  : Created by zhouwanchun.                        #
    # Wechat  : loveoracle11g                                  #
    # Function: This scripts function is ...                   #
    # Version : v1.1                                           #
    ############################################################
    33[0m""")
    
    
    # 连接数据库账号
    conn_user = 'dba'
    
    print("""33[1;35m
    创建管理账号,请输入 : manager
    创建开发账号,请输入 : dev
    33[0m""")
    
    choices = input("请输入你要创建的账号类型 : ").strip()
    
    def create_mysql_user():
        user = input("请设置user : ").strip()
        host = input("请设置host : ").strip()
        password = input("请设置密码 : ").strip()
        create_user = "create user " + "'" + user + "'" + "@" + "'" + host + "'" + " identified by " + "'" + password + "';"
        if choices == 'manager':
            grant_user = "grant all privileges on *.* to " + "'" + user + "'" + "@" + "'" + host + "'" + " with grant option;"
        else:
            grant_user = "grant SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE TEMPORARY TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER on *.* to " + "'" + user + "'" + "@" + "'" + host + "'" + " with grant option;"
        show_grants = "show grants for " + "'" + user + "'" + "@" + "'" + host + "';"
        subprocess.run(['/usr/local/mysql/bin/mysql --login-path=' + conn_user + ' -e ' + '"' + create_user + '"'], shell=True)
        subprocess.run(['/usr/local/mysql/bin/mysql --login-path=' + conn_user + ' -e ' + '"' + grant_user + '"'], shell=True)
        subprocess.run(['/usr/local/mysql/bin/mysqladmin --login-path=' + conn_user + ' flush-privileges'], shell=True)
        subprocess.run(['/usr/local/mysql/bin/mysql --login-path=' + conn_user + ' -e ' + '"' + show_grants + '"'], shell=True)
        return
    
    
    if choices == 'manager':
        create_mysql_user()
    elif choices == 'dev':
        create_mysql_user()
    else:
        print("33[1;31m你输入有误!33[0m")
  • 相关阅读:
    adb常用命令和工具
    playwright学习记录
    vue,element-ui表格,多个单元格值可修改(点击聚焦后变成input,失去焦点请求保存)
    vue,element-ui表格,合并单元格,如果需要合并的数据隔行,需要重新排列数组
    cas-5.3.x接入REST登录认证,移动端登录解决方案
    企业级cas5.3登录页面修改
    cas实现单点登录mysql,oracle双版本
    Mycat实现MySQL主从复制和读写分离(双主双从)
    IDEA安装插件后默认存放的位置
    值得推荐的Idea十几大优秀插件
  • 原文地址:https://www.cnblogs.com/zhouwanchun/p/13269503.html
Copyright © 2011-2022 走看看