如何查看mysql的元数据
创建了很多的存储过程了,他们也都保存在mysql数据库中,如果我们要查看mysql实际上保存了什么信息,可以有四种方法,两种使用show语句,两种使用select语句,他们的格式如下:
SHOW CREATE PROCEDURE / SHOW CREATE FUNCTION
SHOW PROCEDURE STATUS / SHOW FUNCTION STATUS
SELECT FROM MYSQL.PROC
SELECT FROM INFORMATION_SCHEMA
下面针对以上几种语句举例说明一下。
1、使用show create procedure获得存储过程的信息,和show create table等mysql语法类似,这条语句不返回创建时设定的返回值,而是返回过程的语句信息:
mysql> show create procedure pro1//
+-----------+----------+-------------------------------------------------------------------------------+
| Procedure | sql_mode | Create Procedure |
+-----------+----------+-------------------------------------------------------------------------------+
| pro1 | | CREATE DEFINER=`root`@`localhost` PROCEDURE `pro1`()
begin
declare x int;
declare y int;
set x=2;
set y=2;
insert into t1(filed) values(a);
select filed * a from t1 where filed >=b;
end |
+-----------+----------+-------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show create procedure p1//
+-----------+----------+----------------------------------+
| Procedure | sql_mode | Create Procedure |
+-----------+----------+----------------------------------+
| p1 | | CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
select * from db1 |
+-----------+----------+----------------------------------+
1 row in set (0.00 sec)
2、执行show procedure status,这种方法可以返回更多信息的细节:
mysql> show procedure status like 'pro1'//
+-----+------+-----------+----------------+---------------------+---------------------+---------------+---------+
| Db | Name | Type | Definer | Modified | Created | Security_type | Comment |
+-----+------+-----------+----------------+---------------------+---------------------+---------------+---------+
| db1 | pro1 | PROCEDURE | root@localhost | 2010-06-26 10:20:45 | 2010-06-26 10:20:45 | DEFINER | |
+-----+------+-----------+----------------+---------------------+---------------------+---------------+---------+
1 row in set (0.00 sec)