To view objects in MySQL

Source: Internet
Author: User


Table:

Select Table_schema,table_name,table_type,engine from Information_schema.tables where Table_schema not in (' Performance_schema ', ' information_schema ', ' MySQL ');

View:

Select Table_schema,table_name from information_schema.tables where table_type= ' view ';

Index:

SELECT Table_schema,table_name,index_name,index_type from INFORMATION_SCHEMA. STATISTICS;



Stored procedures:

Select Db,name from Mysql.proc;


Function:

SELECT * FROM Mysql.func


Event:

Select Db,name from Mysql.event;



Trigger:

Select Trigger_schema,trigger_name from Information_schema. ' TRIGGERS ';

Constraints

Select Table_schema,table_name,constraint_name,constraint_type from Information_schema. ' Table_constraints ';


FOREIGN key:

Select Constraint_schema, TABLE_NAME, constraint_name, referenced_table_name from ' Information_schema '. referential_constraints;



Determine if all tables have a primary key:


SELECT

Table_schema,table_name

From

Information_schema. TABLES

WHERE

Table_schema not in (' Information_schema ', ' performance_schema ', ' sys ', ' MySQL ') and

TABLE_NAME Not IN (

SELECT

table_name

From

Information_schema.table_constraints T

JOIN information_schema.key_column_usage k USING (

Constraint_name,

Table_schema,

table_name

)

WHERE

T.constraint_type = ' PRIMARY KEY '

and T.table_schema not in (' Information_schema ', ' performance_schema ', ' sys ', ' MySQL ')

);


Count the amount of data in a MySQL database


SELECT Table_schema,table_name,engine,table_rows,avg_row_length,concat (ROUND (data_length/1024/1024/1024,2), ' G ') "Data_length", Concat (ROUND (index_length/1024/1024/1024,2), ' G ') "Index_length", Concat (ROUND (index_length/1024/ 1024/1024) + (data_length/1024/1024/1024), 2), ' G ') "Total", table_collation,create_time from

Information_schema. TABLES WHERE table_schema = ' xxx ' ORDER by table_rows DESC;


To view objects in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.