MYSQL判断某个表是否已经存在

时间:2023-03-09 06:52:59
MYSQL判断某个表是否已经存在
方法一、
You don't need to count anything. SELECT 1 FROM testtable LIMIT 1;
If there's no error, table exists.

方法二、
Or, if you want to be correct, use INFORMATION_SCHEMA. SELECT *
FROM information_schema.tables
WHERE table_schema = 'yourdb'
AND table_name = 'testtable'
LIMIT 1; 方法三、
Alternatively, you can use SHOW TABLES SHOW TABLES LIKE 'yourtable';
If there is a row in the resultset, table exists. 个人觉得方法三很不错

FROM: http://*.com/questions/8829102/mysql-check-if-table-exists-without-using-select-from#8829109