首先解釋一下什麼是元數據,所謂元數據,就是表示數據的數據,這些數據五花八門,總之,只要不是我們存儲到數據庫裡的數據,大多都可以理解為元數據。那麼我們如何來獲取這些元數據呢?
總的來說,有三種思路,第一種,各種show,第二種,各種select,第三種,是mysql的命令行下的命令,不是sql語句。
我們首先看第一種,這裡我列舉一下大家比較熟悉的show語句的用法,其實咱們經常用show來查看信息,比如:
show databases; show tales; show create table 表名; show index from 表名; ....等等
第二種就是通過select來從mysql數據庫或者information_schema數據庫中提取相關信息,比如可以從tables這個表裡面的free_data字段來查看數據碎片的相關信息,這裡我上一篇博文已經介紹過了,這裡就不廢話了。
第三種就是通過mysql自帶的一些命令來查看,這個需要咱們的用戶名和密碼的,下面是我查看相應元數據的代碼,希望能幫到您:
Microsoft Windows [版本 6.1.7601] 版權所有 (c) 2009 Microsoft Corporation。保留所有權利。 C:\Users\Administrator>mysqlshow -u root -proot mysqlshow: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | xinxing | +--------------------+ C:\Users\Administrator>mysqlshow -u root -proot xinxing mysqlshow: [Warning] Using a password on the command line interface can be insecure. Database: xinxing +--------+ | Tables | +--------+ | xin | +--------+ C:\Users\Administrator>mysqlshow -u root -proot --status xinxing mysqlshow: [Warning] Using a password on the command line interface can be insecure. Database: xinxing +------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+------- ----+----------------+---------------------+---------------------+---------------------+-----------------+----------+--- -------------+---------+ | Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_f ree | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Cr eate_options | Comment | +------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+------- ----+----------------+---------------------+---------------------+---------------------+-----------------+----------+--- -------------+---------+ | xin | MyISAM | 10 | Fixed | 3 | 121 | 363 | 34058472181989375 | 1024 | 0 | | 2014-08-25 13:19:02 | 2014-08-25 13:41:25 | 2014-08-25 13:41:25 | utf8_general_ci | | | | +------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+------- ----+----------------+---------------------+---------------------+---------------------+-----------------+----------+--- -------------+---------+ C:\Users\Administrator>
下面是我用mysqldump來查看表結構的一些操作,希望對您有用:
C:\Users\Administrator>mysqldump -u root -proot --no-data xinxing xin mysqldump: [Warning] Using a password on the command line interface can be insecure. -- MySQL dump 10.13 Distrib 5.7.3-m13, for Win64 (x86_64) -- -- Host: localhost Database: xinxing -- ------------------------------------------------------ -- Server version 5.7.3-m13 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `xin` -- DROP TABLE IF EXISTS `xin`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `xin` ( `c` char(40) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2014-08-25 20:49:08
辛星,期待您的關注。。