查询元数据信息
2015-12-15 14:43
411 查看
旭东 带你提升工作中的B格,解决需求
日常工作中,遇到类似下面的应用场景:
删除数据库test下所有前缀为don的表;将数据库test下面所有存储引擎为MyISAM的表改为InnoDB.
5.0之后,提供一个新的数据库information_schema,用来记录MySQL中元数据信息。元数据指的是数据的数据,比如表明、列名、列类型、索引名等表的各种属性。
它是一个虚拟数据库,物理上并不存在相关的目录和文件;库里show tables显示的各种”表”也并不是实际存在的物理表,而全部是视图。
删除test库下面所有前缀以don开头的表
MariaDB [test]> select concat('droptable test.',table_name,';') from information_schema.tables wheretable_schema='test' and table_name like 'don%';+-------------------------------------------+
| concat('drop table test.',table_name,';')|
+-------------------------------------------+
| drop table test.dong; |
| drop table test.dong_ha; |
| drop table test.dong_xi; |
+-------------------------------------------+
3 rows in set (0.00 sec)
将test库下所有myisam引擎更改为innodb引擎
MariaDB [test]> select concat('altertable test.',table_name,' engine=innodb;') from information_schema.tables wheretable_schema='test' and engine='myisam';+----------------------------------------------------------+
| concat('alter table test.',table_name,'engine=innodb;') |
+----------------------------------------------------------+
| alter table test.dong_wwengine=innodb; |
+----------------------------------------------------------+
1 row in set (0.00 sec)
常用的视图
SCHEMATA:提供了当前mysql实例中所有的数据库信息,showdatabases的结果取之此表TABLES:该表提供了关于数据库中的表信息(包括视图),详细表述了某个表数据哪个schema、表类型、表引擎、创建时间等信息。Show tables from schemaname的结果取之此表
COLUMNS:该表提供了表中的列信息,详细表述了某张表的所有列以及每列的信息。Show columns from schemaname.tablename的结果取之此表
STATISTICS:该表提供了关于索引的信息。Show indexfrom schemaname.tablename的结果取之此表。
本文出自 “晴空” 博客,谢绝转载!
相关文章推荐
- SVN:版本库管理
- 高维降维,TSNE. 我CNM,连中文的wiki都访问不了,还TMD让不让人查点东西了
- struts1——静态ActionForm与动态ActionForm
- extundelete恢复文件
- Android性能中容易忽视的优化点有哪些?
- 秒杀多线程第六篇 经典线程同步 事件Event
- 秒杀多线程第五篇 经典线程同步 关键段CS
- Maven那点事儿(Eclipse版)
- c++智能指针:boost::scoped_ptr,boost::shared_ptr,boost::scoped_array
- 网站的Information Architecture--构建一个最优用户体验的site structure
- SVN:使用命令行模式访问SVN服务器
- STM32F303X单片机USB例程详细解析2
- 关于servlet开发时,web.xml的配置问题。
- firedac数据集控件的公共祖先类——TFDAdaptedDataSet
- 自定义 Core Data 迁移
- Intel Edison 移植boa
- mysql备份
- MyBatis学习六:缓存
- JavaScript我的常用函数库
- JavaScript我的常用函数库