rewrite mysql lib. improve documentation

Rewrite mysql lib. Replace the deprecated lib with mysqli and add
support for shared and exclusive mode.