Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SHOW DATABASES statement to view or display database in MySQL

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to use SHOW DATABASES statements to view or display the database in MySQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Example 1: view all databases

List all databases that can be viewed by the current user:

Mysql > SHOW DATABASES

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | sakila |

| | sys |

| | world |

+-+

6 row in set (0.22 sec)

You can find that there are 6 databases in the above list, all of which are automatically created by the system when MySQL is installed, and their respective functions are as follows:

Information_schema: mainly stores some database object information in the system, such as user table information, column information, permission information, character set information and partition information.

The core database of mysql:MySQL, similar to the master table in SQL Server, is mainly responsible for storing the control and management information that MySQL needs to use, such as database users, user access rights and so on. Commonly used, such as changing the root user password in the user table of the mysql database.

Performance_schema: mainly used to collect database server performance parameters.

Sakila:MySQL provides a sample database, the database has a total of 16 tables, these data tables are relatively common, when designing the database, you can refer to these sample data tables to quickly complete the required data tables.

The installation of sys:MySQL 5.7 will result in an additional sys database. The sys database mainly provides some views, and the data comes from performation_schema, mainly to make it easier for developers and users to view performance issues.

World:world database is a database created automatically by MySQL, which contains only three data tables, which store the language used by city, country and country, etc.

Example 2: create and view a database

First create a database called test_db:

Mysql > CREATE DATABASE test_db

Query OK, 1 row affected (0.12 sec)

Then use the SHOW DATABASES statement to display all database names within the scope of permissions, as follows:

Mysql > SHOW DATABASES

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | sakila |

| | sys |

| | test_db |

| | world |

+-+

7 row in set (0.22 sec)

You see, the database just created has been displayed.

Example 3: using LIKE clauses

First create three databases, named test_db, db_test, and db_test_db.

1) use the LIKE clause to view the database that exactly matches the 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 the database whose name begins 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 the database whose name ends in db:

Mysql > SHOW DATABASES LIKE'% db'

+-+

| | Database (% db) |

+-+

| | db_test_db |

+-+

| | test_db |

+-+

2 row in set (0.03 sec)

After reading the above, do you have any further understanding of how to use SHOW DATABASES statements to view or display the database in MySQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report