查看mysql元数据

Metadata元数据

查看mysql保存信息的四种方法:两种使用show语句,两种使用select语句。
SHOW CREATE PROCEDURE / SHOW CREATE FUNCTION
SHOW PROCEDURE STATUS / SHOW FUNCTION STATUS
SELECT from mysql.proc
SELECT from information_schema

mysql> show create procedure p5;//
+-----------+----------+------------------------------------------------------------------+
| Procedure | sql_mode | Create Procedure                                                 |
+-----------+----------+------------------------------------------------------------------+
| p5        |          | CREATE DEFINER=`root`@`localhost` PROCEDURE `p5`(p int)
set @x=p |
+-----------+----------+------------------------------------------------------------------+
1 row in set (0.05 sec)

mysql> show procedure status;//
+-----+--------+-----------+----------------+---------------------+---------------------+---------------+---------+
| Db  | Name   | Type      | Definer        | Modified            | Created             | Security_type | Comment |
+-----+--------+-----------+----------------+---------------------+---------------------+---------------+---------+
| db5 | cc     | PROCEDURE | root@localhost | 2014-03-03 17:22:03 | 2014-03-03 17:22:03 | DEFINER       |         |
| db5 | dd     | PROCEDURE | root@localhost | 2014-03-03 17:23:32 | 2014-03-03 17:23:32 | DEFINER       |         |
| db5 | myloop | PROCEDURE | root@localhost | 2014-03-04 12:26:50 | 2014-03-04 12:26:50 | DEFINER       |         |
| db5 | p1     | PROCEDURE | root@localhost | 2014-03-03 16:23:26 | 2014-03-03 16:23:26 | DEFINER       |         |
| db5 | p10    | PROCEDURE | root@localhost | 2014-03-03 17:13:14 | 2014-03-03 17:13:14 | DEFINER       |         |
| db5 | p12    | PROCEDURE | root@localhost | 2014-03-03 17:28:38 | 2014-03-03 17:28:38 | DEFINER       |         |
| db5 | p13    | PROCEDURE | root@localhost | 2014-03-04 10:39:59 | 2014-03-04 10:39:59 | DEFINER       |         |
| db5 | p14    | PROCEDURE | root@localhost | 2014-03-04 10:46:31 | 2014-03-04 10:46:31 | DEFINER       |         |
| db5 | p15    | PROCEDURE | root@localhost | 2014-03-04 12:10:59 | 2014-03-04 12:10:59 | DEFINER       |         |
| db5 | p2     | PROCEDURE | root@localhost | 2014-03-03 16:27:46 | 2014-03-03 16:27:46 | DEFINER       |         |
| db5 | p200   | PROCEDURE | root@localhost | 2014-03-04 16:34:58 | 2014-03-04 16:34:58 | DEFINER       |         |
| db5 | p22    | PROCEDURE | root@localhost | 2014-03-04 16:18:07 | 2014-03-04 16:18:07 | DEFINER       |         |
| db5 | p222   | PROCEDURE | root@localhost | 2014-03-04 16:20:49 | 2014-03-04 16:20:49 | DEFINER       |         |
| db5 | p2222  | PROCEDURE | root@localhost | 2014-03-04 16:23:35 | 2014-03-04 16:23:35 | DEFINER       |         |
| db5 | p25    | PROCEDURE | root@localhost | 2014-03-05 10:27:03 | 2014-03-05 10:27:03 | DEFINER       |         |
| db5 | p26    | PROCEDURE | root@localhost | 2014-03-05 11:34:23 | 2014-03-05 11:34:23 | INVOKER       |         |
| db5 | p27    | PROCEDURE | root@localhost | 2014-03-05 11:36:11 | 2014-03-05 11:36:11 | DEFINER       |         |
| db5 | p3     | PROCEDURE | root@localhost | 2014-03-03 16:36:12 | 2014-03-03 16:36:12 | DEFINER       |         |
| db5 | p5     | PROCEDURE | root@localhost | 2014-03-03 16:43:18 | 2014-03-03 16:43:18 | DEFINER       |         |
| db5 | p6     | PROCEDURE | root@localhost | 2014-03-03 17:01:01 | 2014-03-03 17:01:01 | DEFINER       |         |
| db5 | p7     | PROCEDURE | root@localhost | 2014-03-03 16:46:22 | 2014-03-03 16:46:22 | DEFINER       |         |
| db5 | p71    | PROCEDURE | root@localhost | 2014-03-03 17:06:34 | 2014-03-03 17:06:34 | DEFINER       |         |
| db5 | p8     | PROCEDURE | root@localhost | 2014-03-03 17:08:51 | 2014-03-03 17:08:51 | DEFINER       |         |
| db5 | pp     | PROCEDURE | root@localhost | 2014-03-04 12:23:01 | 2014-03-04 12:23:01 | DEFINER       |         |
+-----+--------+-----------+----------------+---------------------+---------------------+---------------+---------+
24 rows in set (0.03 sec)

mysql> select * from db5.proc where name='p8';//
ERROR 1146 (42S02): Table 'db5.proc' doesn't exist
mysql> select * from mysql.proc where name='p8';//
+-----+------+-----------+---------------+----------+-----------------+------------------+---------------+------------+---------+---------------------------------------------------------------------------------------------------------------------+----------------+---------------------+---------------------+----------+---------+
| db  | name | type      | specific_name | language | sql_data_access | is_deterministic | security_type | param_list | returns | body                                                                                                                | definer        | created             | modified            | sql_mode | comment |
+-----+------+-----------+---------------+----------+-----------------+------------------+---------------+------------+---------+---------------------------------------------------------------------------------------------------------------------+----------------+---------------------+---------------------+----------+---------+
| db5 | p8   | PROCEDURE | p8            | SQL      | CONTAINS_SQL    | NO               | DEFINER       |            |         | begin
declare a int;
declare b int;
set a=5;
set b=5;
insert into t values(a);
select s1* a from t where s1>=b;
end | root@localhost | 2014-03-03 17:08:51 | 2014-03-03 17:08:51 |          |         |
+-----+------+-----------+---------------+----------+-----------------+------------------+---------------+------------+---------+---------------------------------------------------------------------------------------------------------------------+----------------+---------------------+---------------------+----------+---------+
1 row in set (0.05 sec)

mysql> select table_name,column_name,column_type from information_schema.columns where table_name='routines';//
+------------+--------------------+--------------+
| table_name | column_name        | column_type  |
+------------+--------------------+--------------+
| ROUTINES   | SPECIFIC_NAME      | varchar(64)  |
| ROUTINES   | ROUTINE_CATALOG    | varchar(512) |
| ROUTINES   | ROUTINE_SCHEMA     | varchar(64)  |
| ROUTINES   | ROUTINE_NAME       | varchar(64)  |
| ROUTINES   | ROUTINE_TYPE       | varchar(9)   |
| ROUTINES   | DTD_IDENTIFIER     | varchar(64)  |
| ROUTINES   | ROUTINE_BODY       | varchar(8)   |
| ROUTINES   | ROUTINE_DEFINITION | longtext     |
| ROUTINES   | EXTERNAL_NAME      | varchar(64)  |
| ROUTINES   | EXTERNAL_LANGUAGE  | varchar(64)  |
| ROUTINES   | PARAMETER_STYLE    | varchar(8)   |
| ROUTINES   | IS_DETERMINISTIC   | varchar(3)   |
| ROUTINES   | SQL_DATA_ACCESS    | varchar(64)  |
| ROUTINES   | SQL_PATH           | varchar(64)  |
| ROUTINES   | SECURITY_TYPE      | varchar(7)   |
| ROUTINES   | CREATED            | datetime     |
| ROUTINES   | LAST_ALTERED       | datetime     |
| ROUTINES   | SQL_MODE           | longtext     |
| ROUTINES   | ROUTINE_COMMENT    | varchar(64)  |
| ROUTINES   | DEFINER            | varchar(77)  |
+------------+--------------------+--------------+
20 rows in set (0.05 sec)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值