Fixed mysql connection bugs