Creating MySQL stored procedures involves creating a set of SQL statements, Name and store them in MySQL as a group. This way it can be reused and shared by multiple programs, while also gaining some important advantages.
Photo credits: Peterpal
One of the most beneficial reasons to create MySQL stored procedures is the additional layer of security. that is placed on the databaseA database is an organized set of information that allows you to store, Manage and retrieve data efficiently. Used in various applications, from enterprise systems to online platforms, Databases can be relational or non-relational. Proper design is critical to optimizing performance and ensuring information integrity, thus facilitating informed decision-making in different contexts.... of the application requesting data. If the user account created for the application or web portal is set up with execution-only permissions, the user account will not be able to directly access the following tables.
This helps prevent a hacker from directly accessing the database tables. El riesgo en el que se incurre si un pirata informático utiliza esa cuenta de usuario que ejecuta un procedimiento almacenadoA stored procedure is a set of SQL statements that are stored in a database and can be executed repetitively. Its use allows for optimized performance and security, as it facilitates the management of complex operations and reduces the risk of errors. What's more, stored procedures can accept parameters, lo que los hace versátiles para diversas aplicaciones dentro de la gestión de datos.... es mucho menor que con una cuenta de usuario que tiene permisos completos de inserción, actualización y eliminación de forma directa en las tablas.
Control de acceso al crear procedimientos almacenados mysql
In practice, al crear procedimientos almacenados de mysql, es factible usar algunas reglas que facilitan el control de la cuenta Puede especificar un usuario en un atributo DEFINER de objeto. These are the following:
- Que solo es factible especificar un valor DEFINER que no sea su propia cuenta, si tiene el SÚPER privilegio.
- Que el único valor de usuario legal para todos los que no disponen el privilegio SUPER es su propia cuenta, whether it has been specified literally or through the use of CURRENT_USER, making it impossible to set the definer to any other account.
Another advantage of creating MySQL stored procedures is that it can minimize the potential risk of the stored program and see the creation and usage. To do this, simply follow these guidelines:
- Use the SQL SECURITY INVENTORY in the object definition whenever feasible for a stored routine or view, since this can only be used by users with the appropriate privileges for the operations performed by the object.
- Specify an explicit DEFINER attribute when creating stored programs or views in the context of the definer, while using an account that has the SUPER privilege, since that attribute will refer to an account that only has the privileges required for the operations performed by the object. Only in cases where it is absolutely necessary, an account with many privileges could be specified as DEFINER.
- Prevent users from specifying DEFINER accounts with many privileges, something that, as administrators, this can be achieved by creating MySQL stored procedures, as long as they are not granted the SUPER privilege.
- Describe objects in the DEFINER context considering that they may have access to data for which the invoking user does not have privileges. In some cases, reference to these objects can be avoided if specific privileges are not granted to unauthorized users. For this, It would be enough to determine that users without the EXECUTE privilege cannot refer to stored functions or procedures, and that users with the appropriate privilege can never refer to a view (as would be the case, as an example, of SELECTThe command "SELECT" is fundamental in SQL, used to query and retrieve data from a database. Allows you to specify columns and tables, filtering results using clauses such as "WHERE" and ordering with "ORDER BY". Its versatility makes it an essential tool for data manipulation and analysis, facilitating the obtaining of specific information efficiently.... for select or INSERTThe term "INSERT" refers to the action of aggregating data into a database or system. In the context of programming, is commonly used in SQL languages to insert new rows into a table. This process is essential to maintain the integrity and updating of the information. Proper use of the INSERT instruction contributes to efficiency and effectiveness in data management.... for insert).
Despite this, do not forget that this type of security measure when creating MySQL stored procedures cannot be applied to triggers and events, since they do not have an SQL SECURITY feature and always run in a definitional context, so there is no user to refer to them directly.
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/es_ES/all.js#xfbml=1&status=0”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, 'facebook-jssdk'));



