[root@server51 ~]# mysql -hlocalhost -uroot -p'123qqq...A'#登录MySQL服务
#DELIMITER指令修改SQL语句结束符
mysql> SELECT USER(); #;结束SQL语句
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.01 sec)
mysql> DELIMITER // #定义//为SQL语句结束符
mysql> SELECT USER()// #测试
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> DELIMITER ; #定义;为SQL语句结束符
mysql> SELECT USER(); #测试
+----------------+
| USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
#创建存储过程
mysql> USE tarena; #切换到tarena库
mysql> DELIMITER // #声明//为定界符,方便定义存储过程
mysql> CREATE PROCEDURE stat() #定义存储过程
-> BEGIN
-> SELECT COUNT(*) FROM tarena.departments;
-> SELECT COUNT(*) FROM tarena.employees;
-> END
-> //
mysql> DELIMITER ; #声明;为定界符,方便后续操作
#调用存储过程
mysql> CALL stat(); #CALL关键字
mysql> CALL tarena.stat();
#查看存储过程
mysql> SHOW PROCEDURE STATUS\G #查看所有存储过程
mysql> DESC mysql.proc\G #用于存储存储过程的表
mysql> SELECT * FROM mysql.proc WHERE db='tarena' ANDname='stat';
mysql> SELECT db,name,body FROM mysql.proc WHERE db='tarena' ANDname='stat';
#删除存储过程
mysql> DROP PROCEDURE stat; #删除存储过程