跳转至

Mysql 存储过程


2017-09-19 by dongnan

举个栗子

查看 mysql 存储过程。

查看全部的存储过程

show procedure status \G;

查看指定的存储过程

show procedure status where db='target-db' \G;
*************************** 1. row ***************************
                  Db: target-db
                Name: test_order_check_xr
                Type: PROCEDURE
             Definer: root@%
            Modified: 2017-07-26 16:08:51
             Created: 2017-07-26 16:08:51
       Security_type: DEFINER
             Comment:
character_set_client: latin1
collation_connection: latin1_swedish_ci
  Database Collation: utf8_general_ci
1 row in set (0.01 sec)

通过 mysql.proc 表查询

select `name` from mysql.proc where db = 'target-db' and `type` = 'PROCEDURE' \G;
*************************** 1. row ***************************
name: test_order_check_xr
1 row in set (0.00 sec)

查看存储过程的结构

use target-db;
show create procedure `test_order_check_xr` \G;
# ...省略

导出存储过程

mysqldump 导出时附带存储过程

mysqldump -uroot -p -hlocalhost --opt --single-transaction -R demo > demo.sql

# 注意,参数 `-R`
-R, --routines      Dump stored routines (functions and procedures).

参考

跟我学MySQL存储过程

回到页面顶部