自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL常用查詢Databases和Tables

數(shù)據(jù)庫 MySQL
本篇文章分享一下工作中常見的MySQL腳本,具體內(nèi)容如下,我們一起來看。

分享一下工作中常見的mysql腳本,此次分享的內(nèi)容如下:

  • Databases
  • tables

一、Databases and schemas

列出了 MySQL 實例上的用戶數(shù)據(jù)庫(模式):

select schema_name as database_name
from information_schema.schemata
where schema_name not in('mysql','information_schema',
'performance_schema','sys')
order by schema_name

說明:database_name - 數(shù)據(jù)庫(模式)名稱。

二、Tables

1. 列出 MySQL 數(shù)據(jù)庫中的表

下面的查詢列出了當(dāng)前或提供的數(shù)據(jù)庫中的表。要列出所有用戶數(shù)據(jù)庫中的表

(1) 當(dāng)前數(shù)據(jù)庫

select table_schema as database_name,
table_name
from information_schema.tables
where table_type = 'BASE TABLE'
and table_schema = database()
order by database_name, table_name;

說明:

  • table_schema - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名

(2) 指定數(shù)據(jù)庫

select table_schema as database_name,
table_name
from information_schema.tables
where table_type = 'BASE TABLE'
and table_schema = 'database_name' -- enter your database name here
order by database_name, table_name;

說明:

  • table_schema - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名

2. 列出 MySQL 中所有數(shù)據(jù)庫的表

下面的查詢列出了所有用戶數(shù)據(jù)庫中的所有表:

select table_schema as database_name,
table_name
from information_schema.tables
where table_type = 'BASE TABLE'
and table_schema not in ('information_schema','mysql',
'performance_schema','sys')
order by database_name, table_name;

說明:

  • table_schema - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名

3. 列出 MySQL 數(shù)據(jù)庫中的 MyISAM 表

select table_schema as database_name,
table_name
from information_schema.tables tab
where engine = 'MyISAM'
and table_type = 'BASE TABLE'
and table_schema not in ('information_schema', 'sys',
'performance_schema','mysql')
-- and table_schema = 'your database name'
order by table_schema,
table_name;

說明:

  • database_name - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名

4. 列出 MySQL 數(shù)據(jù)庫中的 InnoDB 表

select table_schema as database_name,
table_name
from information_schema.tables tab
where engine = 'InnoDB'
and table_type = 'BASE TABLE'
and table_schema not in ('information_schema', 'sys',
'performance_schema','mysql')
-- and table_schema = 'your database name'
order by table_schema,
table_name;

說明:

  • database_name - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名

5. 識別 MySQL 數(shù)據(jù)庫中的表存儲引擎(模式)

select table_schema as database_name,
table_name,
engine
from information_schema.tables
where table_type = 'BASE TABLE'
and table_schema not in ('information_schema','mysql',
'performance_schema','sys')
-- and table_schema = 'your database name'
order by table_schema,
table_name;

說明:

(1)table_schema - 數(shù)據(jù)庫(模式)名稱

(2)table_name - 表名

(3)engine- 表存儲引擎??赡艿闹担?/p>

  • CSV
  • InnoDB
  • 記憶
  • MyISAM
  • 檔案
  • 黑洞
  • MRG_MyISAM
  • 聯(lián)合的

6. 在 MySQL 數(shù)據(jù)庫中查找最近創(chuàng)建的表

select table_schema as database_name,
table_name,
create_time
from information_schema.tables
where create_time > adddate(current_date,INTERVAL -60 DAY)
and table_schema not in('information_schema', 'mysql',
'performance_schema','sys')
and table_type ='BASE TABLE'
-- and table_schema = 'your database name'
order by create_time desc,
table_schema;

MySQL 數(shù)據(jù)庫中最近 60 天內(nèi)創(chuàng)建的所有表,按表的創(chuàng)建日期(降序)和數(shù)據(jù)庫名稱排序

說明:

  • database_name - 表所有者,模式名稱
  • table_name - 表名
  • create_time - 表的創(chuàng)建日期

7. 在 MySQL 數(shù)據(jù)庫中查找最近修改的表

select table_schema as database_name,
table_name,
update_time
from information_schema.tables tab
where update_time > (current_timestamp() - interval 30 day)
and table_type = 'BASE TABLE'
and table_schema not in ('information_schema', 'sys',
'performance_schema','mysql')
-- and table_schema = 'your database name'
order by update_time desc;

所有數(shù)據(jù)庫(模式)中最近 30 天內(nèi)最后修改的所有表,按更新時間降序排列

說明:

  • database_name - 數(shù)據(jù)庫(模式)名稱
  • table_name - 表名
  • update_time - 表的最后更新時間(UPDATE、INSERT 或 DELETE 操作或 MVCC 的 COMMIT)
責(zé)任編輯:趙寧寧 來源: 今日頭條
相關(guān)推薦

2021-03-02 12:34:47

MySQL解鎖表鎖定表

2022-05-30 06:30:20

查詢MySQL數(shù)據(jù)庫

2018-03-29 19:45:47

數(shù)據(jù)庫MySQL查詢優(yōu)化

2018-12-24 18:12:41

SQL ServerMySQL數(shù)據(jù)庫

2019-08-14 15:18:55

MySQLSQL數(shù)據(jù)庫

2019-03-25 19:13:37

MySQL常用工具數(shù)據(jù)庫

2018-10-12 16:45:10

MySQL查詢?nèi)罩?/a>數(shù)據(jù)庫

2018-06-07 08:54:01

MySQL性能優(yōu)化索引

2010-11-25 10:21:20

MySql查詢時間段

2021-04-09 23:00:12

SQL數(shù)據(jù)庫Pandas

2009-08-05 10:08:55

MySQL查詢優(yōu)化調(diào)度鎖定

2011-03-03 16:10:04

Mysql數(shù)據(jù)庫備份還原

2017-09-01 21:00:05

MySQLSQL優(yōu)化查詢方法

2021-07-05 09:24:06

MySQL SQL 語句數(shù)據(jù)庫

2013-05-17 10:43:32

2010-05-27 16:12:10

MySQL索引

2017-09-18 15:20:02

MySQL慢查詢?nèi)罩?/a>配置

2010-11-25 13:05:26

MySQL列類型

2022-05-17 08:44:33

數(shù)據(jù)庫MySQL

2021-01-28 23:26:55

MySQL
點贊
收藏

51CTO技術(shù)棧公眾號