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

How to determine whether mysql database exists

WBOY
Release: 2022-05-27 15:33:18
Original
6939 people have browsed it

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%';
Copy after login

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';
Copy after login

How to determine whether mysql database exists

If you simply display whether a database exists, you can use it

show databases like 'db_name';
Copy after login

If you simply display whether a data table exists, you can use

show tables like 'table_name';
Copy after login

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 = '数据库名称';
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template