· 9 years ago · Oct 08, 2016, 11:20 AM
1#!/usr/bin/python
2
3#
4# Modules Import
5#
6import mysql.connector
7from mysql.connector import errorcode
8
9#
10# Variables Definition
11#
12db_config = {
13 'user': '<user>',
14 'password': '<password>',
15 'host': '<rds_endpoint>',
16 'database': 'mysql',
17 'raise_on_warnings': True,
18 'time_zone': 'UTC',
19}
20procedure = 'rds_rotate_general_log'
21
22#
23# Main
24#
25
26# Database connection with error handling
27try:
28 cnx = mysql.connector.connect(**db_config)
29except mysql.connector.Error as err:
30 if (err.errno == errorcode.ER_ACCESS_DENIED_ERROR):
31 print 'Something is wrong with your user name or password'
32 elif (err.errno == errorcode.ER_BAD_DB_ERROR):
33 print 'Database does not exists'
34 else:
35 print err
36else:
37 # Create cursor for query execution
38 cursor = cnx.cursor()
39
40 # Execute stored procedure that rotates general_log table
41 cursor.callproc('rds_rotate_general_log')
42
43 # Print execution result
44 # for result in cursor.stored_results():
45 # print result.fecthall()
46
47 # Close database connection
48 cnx.close()