Method: 1. Use the "show databases like 'database name'" statement to judge; 2. Use the "SELECT * FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'database name'" statement to judge.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
1. MySQL determines whether the table and database exist
SHOW TABLES LIKE SHOW TABLES LIKE '%wp_order%';
TABLE_SCHEMA and TABLE_NAME
select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='dbname' and TABLE_NAME='tablename';
If you simply display whether a database exists, you can use it
show databases like 'db_name';
If you simply display whether a data table exists, you can use
show tables like 'table_name';
If a database with the name "dbname" does not exist, you will get an empty set. If it does exist, you'll get a row.
2. SELECT * FROM statement
SELECT * FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '数据库名称';
Recommended learning: mysql video tutorial
The above is the detailed content of How to determine whether mysql database exists. For more information, please follow other related articles on the PHP Chinese website!