search
HomeDatabaseMysql TutorialHow 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']; ".

How to check which databases are available in MySQL

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!

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
How to enable the slow query log in MySQLHow to enable the slow query log in MySQLAug 26, 2025 am 07:14 AM

To enable MySQL slow query logs, first check the current status: 1. Execute SHOWVARIABLESLIKE'slow_query_log'; if OFF, it needs to be enabled; 2. Check the log path and threshold: SHOWVARIABLESLIKE'slow_query_log_file'; and SHOWVARIABLESLIKE'long_query_time'; 3. It is recommended to modify the configuration file (such as /etc/my.cnf), and add it under [mysqld]: slow_query_log=ON, slow_query_log_file=/var/log/mysql/m

How to find the Nth highest salary in a MySQL table?How to find the Nth highest salary in a MySQL table?Aug 26, 2025 am 06:42 AM

The use of LIMIT and OFFSET is suitable for simple queries and N is known, but does not support dynamic variables; 2. The window function using DENSE_RANK() can correctly handle duplicate values, and it is recommended to use in dynamic N scenarios in modern MySQL versions; 3. The use of related subqueries is suitable for older versions of MySQL that do not support window functions, but have poor performance; the most recommended method is DENSE_RANK(), which is suitable for most production environments due to its accuracy, flexibility and efficiency.

What is the SQL mode in MySQL?What is the SQL mode in MySQL?Aug 26, 2025 am 05:37 AM

SQLmodeinMySQLdefineshowtheserverinterpretsSQLstatementsbycontrollingdatavalidation,syntaxcompliance,andhandlingofinvalidormissingdata,withcommonmodesincludingSTRICT_TRANS_TABLESfordataintegrity,ONLY_FULL_GROUP_BYforstandardGROUPBYbehavior,NO_ZERO_DA

What is the difference between a temporary table and a table variable in MySQL?What is the difference between a temporary table and a table variable in MySQL?Aug 26, 2025 am 04:51 AM

MySQLdoesnotsupporttablevariableslikeSQLServer;2.Theonlybuilt-inoptionfortemporaryresultsetsinMySQLisCREATETEMPORARYTABLE;3.Temporarytablesaresession-specific,supportindexesandjoins,andareautomaticallydroppedwhenthesessionends;4.User-definedvariables

How to get the list of databases on a MySQL server?How to get the list of databases on a MySQL server?Aug 26, 2025 am 04:17 AM

To get the database list on the MySQL server, the most common method is to use the SHOWDATABASES command, and after logging in to MySQL, execute SHOWDATABASES; it can display all databases that the current user has permission to access, and system databases such as information_schema, mysql, performance_schema and sys are usually listed; in addition, the same results can be obtained by querying the INFORMATION_SCHEMA.SCHEMATA table, which is suitable for scenarios where filtering or scripting operations are required, such as using SELECTSCHEMA_NAMEFROMINFORMATION_SCHEMA_SCHEMA_

What is the role of my.cnf or my.ini file in MySQL?What is the role of my.cnf or my.ini file in MySQL?Aug 26, 2025 am 03:49 AM

Themy.cnformy.inifileisessentialforcustomizingMySQLbehavior,asitallowsadministratorstocontrolserversettings,optimizeperformance,managelogs,andapplyconfigurationstospecificcomponents;withoutit,MySQLrunsondefaults,limitingperformance,security,andmonito

What is a foreign key in MySQL?What is a foreign key in MySQL?Aug 26, 2025 am 02:49 AM

AforeignkeyinMySQLisacolumnorsetofcolumnsthatreferencesaprimaryoruniquekeyinanothertabletoenforcereferentialintegrity;itensuresdataconsistencybyallowingonlyvalidvaluesfromthereferencedtable,preventsaccidentaldeletionofrelatedrecordsdependingonconstra

What is the difference between COUNT(*) and COUNT(column) in MySQL?What is the difference between COUNT(*) and COUNT(column) in MySQL?Aug 26, 2025 am 12:56 AM

COUNT()countsallrowsincludingthosewithNULLvalues,whileCOUNT(column)onlycountsrowswherethespecifiedcolumnisnotNULL.1.COUNT()includeseveryrowregardlessofNULLsandisusedtogetthetotalnumberofrows.2.COUNT(column)excludesNULLsinthespecifiedcolumnandisusedto

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Hot Topics