Home >Database >Mysql Tutorial >How to determine whether mysql database exists

How to determine whether mysql database exists

WBOY
WBOYOriginal
2022-05-27 15:33:186973browse

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.

How to determine whether mysql database exists

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to determine whether the mysql database exists

1. MySQL determines whether the table and database exist

SHOW TABLES LIKE
SHOW TABLES LIKE '%wp_order%';

How to determine whether mysql database exists

TABLE_SCHEMA and TABLE_NAME

select TABLE_NAME from INFORMATION_SCHEMA.TABLES where 
TABLE_SCHEMA='dbname' and TABLE_NAME='tablename';

How to determine whether mysql database exists

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn