View the number of records in all tables in the database in mysql

If the version of MySQL is 5.0 and above, you can obtain it by querying the tables table in the information_schema library, which uses table_rows to record the number of rows in the table. For example, to view the number of records of all tables in the library testdb: the
code is as follows
use information_schema;
select table_name,table_rows from tables
where TABLE_SCHEMA = 'testdb'
order by table_rows desc;
but it should be noted that for InnoDB tables, the row count of table_rows is only Approximate estimate.
Another way is to use the tables table of the information_schema library to splice out a sql statement, for example: the
code is as follows copy the code
use information_schema;
select concat(
    'select "',
    TABLE_name,
    '", count(*) from ',
    TABLE_SCHEMA ,
    '.',
    TABLE_name,
    ' union all'
) from tables
where TABLE_SCHEMA='testdb';


TABLE_SCHEMA: database name
TABLE_NAME: table name

ENGINE: storage engine used
TABLES_ROWS: number of records

DATA_LENGTH: data size The result is in bytes, dividing by 1024 is K, dividing by 1048576 (=1024*1024) is M
INDEX_LENGTH: Index size
Code as follows Copy code
use information_schema;

select table_schema, table_name, table_rows from tables order by table_rows desc;

View the specified database size:
Code as follows Copy code
SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA

='database name';


/*mysql common commands*/
-- view the currently used database
select database();

-- get the table structure
DESC logisticsroute;
show columns from logisticsroute;

-- change the table name:- Command: rename table original table name to new table name
rename table myclass2 to myclass4;

from: http://www.111cn.net/database/mysql/45964.htm

mysql command to query the number of tables
SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='dbname';  


Reference: http://blog.csdn.net/yageeart/article/details/7953936

Get mysql installation path through Mysql statement query
select @@basedir as basePath from dual

Reference: http://blog.csdn.net/lixuemei504/article/details/7888945

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326940882&siteId=291194637