sql = "select host, user, authentication_string from mysql.user" source_mysql_cursor.execute(sql)
for host, user, authentication_string in source_mysql_cursor.fetchall(): if user in ignore_users: continue # 创建用户 create_sql = "CREATE USER IF NOT EXISTS '{}'@'{}' IDENTIFIED BY 'skvnajnvr92jkfads'".format( user, host ) # 修改密码 change_password_sql = "UPDATE mysql.user SET authentication_string='{}' WHERE host='{}' AND user='{}'".format( authentication_string, host, user )
# 授权语句获取 grant_sql = "show grants for '{}'@'{}'".format(user, host) source_mysql_cursor.execute(grant_sql) grant_sql_result = source_mysql_cursor.fetchall() target_sql_list.extend([x[0] for x in grant_sql_result])