在MySQL中,我們可以通過以下兩條SQL語句來查詢一個庫或是一個表是否存在:

查詢庫是否存在:

select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_SCHEMA`='your_database_name'

查詢表是否存在:

select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_SCHEMA`='your_database_name' and `TABLE_NAME`='your_table_name'