Uses `SHOW DATABASES` to test existent of database.

The `mysql.user` and `mysql.db` table is used for access privilege.
see http://dev.mysql.com/doc/refman/5.5/en/grant-table-structure.html

A database owned by root may not exists in the `mysql.db` table. So `mysql.database_exists` function may fails if the database is owned by root user.

Use `SHOW DATABASES` instead of `SELECT Db FROM mysql.db`
avoid the problem.