Refactore configuration to allow easy extention

issue3627
review7401002
Use sequence as parameter of query for MySQLdb >= 1.2.5

issue4149
review7531002