Mysql method to query how many tables a database has: 1. Use the MySQL client to log in to the MySQL database server; 2. Use the "USE database name" statement to switch to the specified database; 3. Use "SHOW TABLES; " statement lists all tables in the specified database.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In mysql, you can use the SHOW TABLES
statement to query how many tables there are in the database. This statement can list all tables in the database.
To list all tables in a MySQL database, follow these steps:
Use a MySQL client (such as
mysql
) Log in to the MySQL database serverUse the
USE database name
statement to switch to a specific database.Use the
SHOW TABLES
command.
The following illustrates the syntax of the MySQL SHOW TABLES
command:
SHOW TABLES;
MySQL SHOW TABLES Example
The following example illustrates how to column Export all tables in the yiibaidb
database.
Step 1 - Connect to MySQL database server:
C:\Users\Administrator>mysql -u root -p
Step 2 - Switch to yiibaidb
database:
mysql> USE yiibaidb; Database changed mysql>
Step 3 - Display all tables in yiibaidb
database:
mysql> show tables; +--------------------+ | Tables_in_yiibaidb | +--------------------+ | aboveavgproducts | | article_tags | | bigsalesorder | | contacts | | customerorders | | customers | | departments | | employees | | employees_audit | | officeinfo | | offices | | offices_bk | | offices_usa | | orderdetails | | orders | | organization | | payments | | price_logs | | productlines | | products | | saleperorder | | user_change_logs | | v_contacts | | vps | +--------------------+ 24 rows in set
SHOW TABLES
command can display that the table is a base table Or the view. To include the table type in the results, use the SHOW TABLES
statement as shown below -
SHOW FULL TABLES;
Execute the above statement as shown below-
mysql> SHOW FULL TABLES; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | article_tags | BASE TABLE | | bigsalesorder | VIEW | | contacts | BASE TABLE | | customerorders | VIEW | | customers | BASE TABLE | | departments | BASE TABLE | | employees | BASE TABLE | | employees_audit | BASE TABLE | | officeinfo | VIEW | | offices | BASE TABLE | | offices_bk | BASE TABLE | | offices_usa | BASE TABLE | | orderdetails | BASE TABLE | | orders | BASE TABLE | | organization | VIEW | | payments | BASE TABLE | | price_logs | BASE TABLE | | productlines | BASE TABLE | | products | BASE TABLE | | saleperorder | VIEW | | user_change_logs | BASE TABLE | | v_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 24 rows in set
We are at yiibaidb
Create a view named view_contacts
in the database, which includes the first name, last name and phone number from the employees
and customers
tables.
CREATE VIEW view_contacts AS SELECT lastName, firstName, extension as phone FROM employees UNION SELECT contactFirstName, contactLastName, phone FROM customers;
Now, execute the query SHOW FULL TABLES
command:
mysql> SHOW FULL TABLES; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | article_tags | BASE TABLE | | bigsalesorder | VIEW | | contacts | BASE TABLE | | customerorders | VIEW | | customers | BASE TABLE | | departments | BASE TABLE | | employees | BASE TABLE | | employees_audit | BASE TABLE | | officeinfo | VIEW | | offices | BASE TABLE | | offices_bk | BASE TABLE | | offices_usa | BASE TABLE | | orderdetails | BASE TABLE | | orders | BASE TABLE | | organization | VIEW | | payments | BASE TABLE | | price_logs | BASE TABLE | | productlines | BASE TABLE | | products | BASE TABLE | | saleperorder | VIEW | | user_change_logs | BASE TABLE | | v_contacts | VIEW | | view_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 25 rows in set
You can see, v_contacts
,view_contacts
, vps
and so on are views (VIEW), while other tables are base tables (BASE TABLE).
For databases with many tables, it may be intuitive to display all tables at once.
Fortunately, the SHOW TABLES
command provides an option that allows the use of LIKE
operators or expression pairs in a WHERE
clause The returned tables are filtered as follows:
SHOW TABLES LIKE pattern; SHOW TABLES WHERE expression;
For example, to display all tables in the yiibaidb
database that begin with the letters p
, use the following statement:
mysql> SHOW TABLES LIKE 'p%'; +-------------------------+ | Tables_in_yiibaidb (p%) | +-------------------------+ | payments | | price_logs | | productlines | | products | +-------------------------+ 4 rows in set
Or to display tables ending with the string 'es
', you can use the following statement:
mysql> SHOW TABLES LIKE '%es'; +--------------------------+ | Tables_in_yiibaidb (%es) | +--------------------------+ | employees | | offices | | productlines | +--------------------------+ 3 rows in set
The following statement explains how to SHOW TABLES
Use the WHERE
clause in the statement to list all views in the yiibai
database -
mysql> SHOW FULL TABLES WHERE table_type = 'VIEW'; +--------------------+------------+ | Tables_in_yiibaidb | Table_type | +--------------------+------------+ | aboveavgproducts | VIEW | | bigsalesorder | VIEW | | customerorders | VIEW | | officeinfo | VIEW | | organization | VIEW | | saleperorder | VIEW | | v_contacts | VIEW | | view_contacts | VIEW | | vps | VIEW | +--------------------+------------+ 9 rows in set
Sometimes, you want to see tables in the database that are not currently in use. You can use the FROM
clause of the SHOW TABLES
statement to specify the database in which the table is to be displayed.
The following example demonstrates how to display tables starting with 'time
';
mysql> SHOW TABLES FROM mysql LIKE 'time%'; +---------------------------+ | Tables_in_mysql (time%) | +---------------------------+ | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 5 rows in set
The following statement is equivalent to the above statement, but it uses IN
Instead of the FROM
clause, as shown below -
mysql> SHOW TABLES IN mysql LIKE 'time%'; +---------------------------+ | Tables_in_mysql (time%) | +---------------------------+ | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | +---------------------------+ 5 rows in set
Please note that if you do not have permissions on the base table or view, it will not show up in SHOW TABLES
The results of the command are concentrated.
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to query how many tables a database has in mysql. For more information, please follow other related articles on the PHP Chinese website!

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

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