Guest User

Untitled

a guest
Oct 10th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #
  4. # Modules Import
  5. #
  6. import mysql.connector
  7. from mysql.connector import errorcode
  8.  
  9. #
  10. # Variables Definition
  11. #
  12. db_config = {
  13. 'user': '<user>',
  14. 'password': '<password>',
  15. 'host': '<rds_endpoint>',
  16. 'database': 'mysql',
  17. 'raise_on_warnings': True,
  18. 'time_zone': 'UTC',
  19. }
  20. procedure = 'rds_rotate_general_log'
  21.  
  22. #
  23. # Main
  24. #
  25.  
  26. # Database connection with error handling
  27. try:
  28. cnx = mysql.connector.connect(**db_config)
  29. except 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 exist'
  34. else:
  35. print err
  36. else:
  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()
Advertisement
Add Comment
Please, Sign In to add comment