Get the App
SLTechnology News&Howtos  ›  Database  › 

What do mysql dump / restore stored procedures and triggers refer to

Shulou Source: shulou.com Published: 2022-06-01 01:51:52 10月03日 Update

This article will explain in detail what mysql dump / recovery stored procedures and triggers refer to. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

MySQL5.0 first introduced stored procedures and triggers. Therefore, if you are still using an older version of MySQL, you can upgrade it to MySQL 5.0 or later to use these features. This article describes how to dump stored procedures and triggers using the mysqldump command.

What is a stored procedure?

By definition, a stored procedure is a declarative SQL code snippet stored in a database directory that can be called later by programs, triggers, or even stored procedures.

What is a trigger?

Triggers are event-driven specialized processes that are stored in and managed by the database. A trigger is a SQL process that initiates an operation on an event that occurs, such as an insert, delete, or update.

When we simply execute mysqldump, it backs up triggers automatically, but not stored procedures by default.

Backup stored procedures and routines

We need to specify-- routines to back up stored procedures with data and tables.

The following command backs up the entire database, including stored procedures. For example, the database name is "mydb".

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

To back up only stored procedures and triggers (excluding tables and data), use the following command.

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

Recovery program

To restore stored procedures in the database, simply use the following command, but make sure that you have backed up correctly before restoring to avoid any data loss.

$mysql-u root-p mydb < mydb.sql so much about what mysql dump / recovery stored procedures and triggers refer to. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Tags: Procedure storage trigger data backup database command event more version program article good practical code content function just name situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Xiaomi Microsoft Shulou Technology