77

MySQL Dump and Restore,Stored Procedures and Triggers

 5 years ago
source link: https://www.linuxprobe.com/dump-and-restore.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
导读 存储过程和触发器在MySQL 5.0中首先介绍了。所以,如果你还在使用MySQL旧版本的它升级到MySQL 5.0或更高版本才能使用这些功能。 本文将帮助你如何让存储过程转储和使用mysqldump命令触发。
什么是存储过程?

存储过程,是被存储在数据库中的目录,并且可以由一个程序、一个触发器或者甚至一个存储过程以后调用的声明的SQL代码段。

什么是触发器?

触发器是事件驱动的专属程序,它们被存储下来,由数据库管理。触发器是发起一个事件后触发一个SQL过程(像:INSERT,DELETE或UPDATE)都可以触发。

当我们执行mysqldump ,它会自动触发的备份,但默认不会备份存储过程。

备份存储程序和常见的例子

我们需要指定 -routines 参数来完成数据和表的存储过程的备份。 以下命令将包括存储过程的整个数据库的备份。例如你的数据库名称为“mydb”。

# mysqldump -u root -p --routines mydb > mydb.sql

只备份存储过程和触发器(无数据和表格)使用以下命令。

# mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt mydb > mydb.sql

恢复存储过程

要恢复数据库的存储过程使用下面的简单命令,但要确保你已经备份,以避免之前任何数据的丢失。

# mysql -u root -p mydb

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK