Database (data) testing tutorial with sample test cases

      4

Summary: in this tutorial, you will learn how to use the MySQL SHOW DATABASES command to danh sách all databases in a MySQL database server.

Bạn đang xem: Database (data) testing tutorial with sample test cases

Using the MySQL SHOW DATABASES

To menu all databases on a MySQL hệ thống host, you use the SHOW DATABASES command as follows:


Code language: SQL (Structured Query Language) (sql)For example, to menu all database in the local MySQL database server, first login khổng lồ the database server as follows:


mysql> SHOW DATABASES;+--------------------+| Database |+--------------------+| classicmodels || information_schema || mysql || performance_schema || sys || test |+--------------------+6 rows in phối (0.00 sec)
Code language: SQL (Structured Query Language) (sql)The SHOW SCHEMAS command is a synonym for SHOW DATABASES, therefore the following command returns the same result as the one above:


Code language: SQL (Structured Query Language) (sql)If you want to lớn query thedatabase that matches a specific pattern, you use the lượt thích clause as follows:


Code language: SQL (Structured Query Language) (sql)For example, the following statement returns database that ends with the string "schema";


SHOW DATABASES like "%schema";+--------------------+| Database (%schema) |+--------------------+| information_schema || performance_schema |+--------------------+2 rows in mix (0.00 sec)
Code language: SQL (Structured Query Language) (sql)It is important to lưu ý that if the MySQL database hệ thống started with --skip-show-database, you cannot use the SHOW DATABASES statement unless you have the SHOW DATABASES privilege.

Querying database data from information_schema

If the condition in the like clause is not sufficient, you can query the database information directly from the schemata table in the information_schema database.

Xem thêm: Top 5 Cách Chuyển File Pdf Sang Word Không Cần Phần Mềm Tiện Lợi Nhất Năm 2022

For example, the following query returns the same result as the SHOW DATABASES command.


Code language: SQL (Structured Query Language) (sql)The following SELECT statement returns databases whose names over with "schema" or "s".


SELECT schema_nameFROM information_schema.schemataWHERE schema_name lượt thích "%schema" OR schema_name lượt thích "%s";
+--------------------+| SCHEMA_NAME |+--------------------+| information_schema || performance_schema || sys || classicmodels |+--------------------+4 rows in phối (0.00 sec)
Code language: SQL (Structured Query Language) (sql)In this tutorial, you have learned how lớn show all databases in the MySQL vps using the SHOW DATABASES commandorquerying from the schemata table in the information_schema database.


*

*

nhatroso.com is a trang web dedicated lớn MySQL database. We regularly publish useful MySQL tutorials to lớn help web developers & database administrators learn MySQL faster & more effectively. All MySQL tutorials are practical và easy-to-follow, with SQL script và screenshots available. More About Us