Home >Database >Mysql Tutorial >How to check which databases are available in MySQL
In MySQL, you can use the "SHOW DATABASES" statement to view which databases there are. This statement can view or display all databases within the scope of the current user's permissions. The syntax is "SHOW DATABASES [LIKE 'string']; ".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In MySQL, you can use the SHOW DATABASES statement to view or display databases within the scope of the current user's permissions. The syntax format for viewing the database is:
SHOW DATABASES [LIKE '字符串'];
The syntax description is as follows:
The LIKE clause is optional and is used to match the specified database name. The LIKE clause can match partially or completely.
String is surrounded by single quotes ' ', specifying the string used to match; "string" can be a complete string, or it can contain wildcards.
#The LIKE keyword supports percent sign "%" and underscore "_" wildcard characters.
Wildcard is a special statement, mainly used for fuzzy queries. Wildcards can be used to replace one or more real characters when the real characters are not known or you are too lazy to enter the full name.
1. Directly use SHOW DATABASES
to view all databases
List all databases that the current user can view:
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sakila | | sys | | test_db | | world | +--------------------+ 7 row in set (0.22 sec)
2. Use LIKE clause and fuzzy query
First create three databases with names: test_db, db_test, db_test_db.
1) Use the LIKE clause to view the database that exactly matches test_db:
mysql> SHOW DATABASES LIKE 'test_db'; +--------------------+ | Database (test_db) | +--------------------+ | test_db | +--------------------+ 1 row in set (0.03 sec)
2) Use the LIKE clause to view the database whose name contains test:
mysql> SHOW DATABASES LIKE '%test%'; +--------------------+ | Database (%test%) | +--------------------+ | db_test | +--------------------+ | db_test_db | +--------------------+ | test_db | +--------------------+ 3 row in set (0.03 sec)
3) Use the LIKE clause to view databases whose names begin with db:
mysql> SHOW DATABASES LIKE 'db%'; +----------------+ | Database (db%) | +----------------+ | db_test | +----------------+ | db_test_db | +----------------+ 2 row in set (0.03 sec)
4) Use the LIKE clause to view databases whose names end with db:
mysql> SHOW DATABASES LIKE '%db'; +----------------+ | Database (%db) | +----------------+ | db_test_db | +----------------+ | test_db | +----------------+ 2 row in set (0.03 sec)
[Related recommendations: mysql video tutorial 】
The above is the detailed content of How to check which databases are available in MySQL. For more information, please follow other related articles on the PHP Chinese website!