查询整个MySQL服务是否存在此表
SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_name = #{tableName}
查询当前库是否存在此表
SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_name = #{tableName} and TABLE_SCHEMA = (select database());
切换库: use [库名称]
查询当前连接的库:select database()
思路:
需要添加一个条件:where TABLE_SCHEMA = (select database())
来指定所使用的库。