How to Show a List of All Databases in MySQL
Last Updated :
08 Jul, 2024
MySQL is a popular open-source relational database management system (RDBMS) that is uniquely used to construct expandable and high-productivity databases. MySQL, which was created by MySQL AB and later acquired by its current owner Oracle Corporation, was originally introduced in 1995.
MySQL is reputed for its sturdy and quick functioning attributes which involve easy-to-handle features and dependability. MySQL can normally be seen together with dynamic web applications and is generally used to serve languages such as PHP but also other server-side programming languages like Python. In this article, you will discover how to list all the databases in MySQL along with some examples.
MySQL Show/List Databases
The MySQL, SHOW DATABASES is used to list the databases that are within the MySQL environment. It prints all the databases including the default system databases. It depends on the user whether they want to print all the databases or some specific databases. We can use 'LIKE', and 'WHERE' clauses to specify the databases that we want to print. There are 4 default system databases in the MySQL environment. Let's study them one by one in detail:
information_schema:
- The information schema database is responsible for the metadata of the MySQL server and its databases, tables, columns, and other objects.
- It gives rise to information resources that are tables and columns, names, data types, character sets and privileges, etc.
, - It is the most popular among database administrators and developers stored in the MySQL database so that they may know the information related to the structure and configuration of their servers.
- It is not intended to store the information; it is made to maneuver data around the database schema which is the skeleton of all the procedures and programming in the database.
mysql:
- MySQL is most useful for keeping system-related data (e.g. user account details, user privileges, and metadata information about the administration).
- Likewise, it may incorporate 5 tables to wit: user, db, tables_priv, columns_priv, and host all hold the information about users, databases, and their permissions.
- Administrators, in turn, employ this database to perform user account management, password landing, and configuration of authentication settings.
- The core functionality of the project is to have the database created with MYSQL Database. We’ll manage user authentication and authorization with this database.
performance_schema:
- The performance_ schema database is the source of information related to the performance of the MySQL server’s operation and resource uses.
- It grabs these data and aggregates them into one place, covering server events, mutexes, file I/O, table vs index access patterns, and so on.
- The Database administrators and developers will use the performance_schema to monitor and analyze the MySQL server performance and detect the point of slowdown to the maximum efficiency of the queries and the configuration.
- It provides the analysis of [the] system, at the resource usage level, the periods of query execution times, and other performance metrics (at both server and session level).
sys:
- sys schema is a group of stored procedures, functions, and views that are not only critical in providing insights into the MySQL server's performance but also provide a source of information as far as the server's configuration is concerned.
- It is based on the structures, performance_schema and information_schema through which the statisticist can have a simplified stand with improved views for performance analysis and monitoring.
- Programming the sys schema with tools like sys.statement_analysis, sys.schema_statistics, sys.innodb_*, and so on (much more).
- It enables the convenient retrieval of issues related to, the metrics and guidelines on the tuning and avoiding of over-utilization resources by MySQL server.
Syntax:
SHOW {DATABASES | SCHEMAS}
[LIKE 'pattern' | WHERE expr];
Explanation:
In the above syntax, we are writing a query to list the databases. It is not compulsory to add the 'LIKE' or the 'WHERE' clause to reference the database. LIKE or WHERE clause is used when we want to list particular databases. Otherwise, if we do not use the LIKE or WHERE clause, all the databases will get listed.
Examples of Show/List Databases
Setting up the environment
Let's first create some databases in MySQL.
CREATE database student;
CREATE database teacher;
CREATE database customer;
CREATE database orders;
CREATE database stud;
Example 1: Show/List all Databases
Let's write a query to Show/List all the databases in MySQL.
SHOW databases;
SHOW schemas;
Output:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| student |
| teacher |
| customer |
| orders |
| stud |
+--------------------+
9 rows in set (0.00 sec)
Explanation: In the above example all the databases will be listed as we are not using the LIKE or WHERE clause. Both Let's queries will give the same output. It will also print the default system databases.
Example 2: Show/List Databases using LIKE
Let's write a query to Show/List all the databases starting with the letter 's'.
SHOW databases LIKE 's%';
SHOW schemas LIKE 's%';
Output:
mysql> SHOW DATABASES LIKE 's%';
+--------------------+
| Database |
+--------------------+
| student |
| stud |
+--------------------+
2 rows in set (0.00 sec)
mysql> SHOW SCHEMAS LIKE 's%';
+--------------------+
| Database |
+--------------------+
| student |
| stud |
+--------------------+
2 rows in set (0.00 sec)
Explanation: In the above example we are printing all the databases whose name starts with s. There are a total of 3 databases whose name starts with 's' including one system database. We are using LIKE keyword to specify the condition.
Example 3: Show/List Databases using WHERE clause
In MySQL, We cannot use the WHERE clause with SHOW DATABASES. Instead, we can fire the queries on the information_schema.SCHEMATA Table.
Let's write a query to Show/List all the databases starting with the letter 's'.
Query:
SELECT schema_name
FROM information_schema.SCHEMATA
WHERE schema_name LIKE 's%';
Output:
mysql> SELECT schema_name
-> FROM information_schema.SCHEMATA
-> WHERE schema_name LIKE 's%';
+--------------------+
| schema_name |
+--------------------+
| student |
| stud |
+--------------------+
2 rows in set (0.00 sec)
Explanation: In the above example we are printing all the schemas whose name starts with s. There are a total of 3 schemas whose name starts with 's' including one system schema. Here we cannot use the WHERE clause directly with SHOW DATABASE so we are using information_schema.SCHEMATA table to use the WHERE clause.
Conclusion
In summary, the SHOW DATABASES command in MySQL turns out to be a powerful tool either for the DBAs or for developers. It gives a short list of databases that are located on the dialed server instance enabling the users to have easy access to the suitable database for purposeful activities such as performing necessary operations and maintenance of objects.
To a great extent, this command has operated as an integrated element of the database monitoring process, solving problems and managing resources, while making new project purchases. Its ease of use and reliability make it a key encoding for any project involving MySQL, keeping data organized and well-managed without a need for complexity.
Similar Reads
How to Show/List Tables in MySQL Database
In MySQL, the SHOW TABLES command is a powerful tool used to list the tables within a specific database. This command provides a convenient way to view the tables that exist in a database without needing to query the database schema directly. In this article, we are going to explore various ways whe
5 min read
How to Show a List of Databases in PL/SQL?
Managing databases is a fundamental aspect of database administration and development. In Oracle Database, schemas represent logical containers for database objects like tables, views, procedures, and functions. PL/SQL is the procedural extension of and used in Oracle Database and provides powerful
5 min read
How to List all Databases in the Mongo Shell?
Knowing how to list databases in MongoDB is an important part of managing your data effectively. By using basic MongoDB shell commands, you can easily see what databases you have and understand their sizes. By using commands such as show dbs and db.stats() and users can gain valuable insights into t
4 min read
How to Show Schema of a Table in MySQL Database?
A table schema in MySQL database defines the structure of table, including columns, data types, relationships between columns, etc. It is a blueprint for the table, describing how data is organized in the table and how it relates to other tables in the database. To see the schema of a table in MySQL
2 min read
How to list the Tables in a SQLite Database File ?
SQLite is a database engine which is written in C programming language. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is
4 min read
How to List All Tables in a Schema in Oracle Database?
In Oracle Database, listing all tables within a schema can be crucial for database management and analysis. we can use specific queries to retrieve information about tables in our schema. Below, we explore various queries to list tables, focusing on the SYSOBJECTS view that provides essential metada
3 min read
How to Show Database in PL/SQL
PL/SQL is the Procedural Language/Structured Query Language and serves as a procedural language built-in extension to SQL language, which allows seamless integration of procedural constructs with SQL. One of the most common functions of a DBMS is the retrieval of information about databases which is
4 min read
List All Databases in SQL Server
In SQL Server, databases are crucial for storing and managing data efficiently. Whether we are managing a large enterprise system or a small application, understanding how to list all the databases on our SQL Server is essential. In this article, we will write SQL queries that help us to retrieve al
3 min read
How to List Databases and Tables in PostgreSQL using PSQL
PostgreSQL is a powerful, open-source object-relational database system. It provides a wide array of tools and features to manage databases, tables, and other database objects. In this article, we will explain how to list databases and tables in PostgreSQL using the psql command-line interface. We w
3 min read
How to Export Database Schema Without Data in SQL?
Database Schema specifies the structure of a database with its components like tables, columns, and indexes. Exporting data in SQL is an essential task in database management used to perform functions like data backup, recovery, migration, data analysis, performance optimization, compliance, auditin
4 min read