Please help me out to execute a MySQL Stored procedure in command line, where the procedure contains conditional statements..
Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.
You can use the command line tool "sqlcmd Utility" from your batch file to connect to a sql server and execute a SQL Statement / stored procedure. you can use SQLCMD to run store procedure from CMD.
MySQL refers to stored procedure execution as calling, and so the MySQL statement to execute a stored procedure is simply CALL . CALL takes the name of the stored procedure and any parameters that need to be passed to it. Take a look at this example: CALL productpricing(@pricelow, @pricehigh, @priceaverage);
Launch the MySQL Command-Line Client. To launch the client, enter the following command in a Command Prompt window: mysql -u root -p . The -p option is needed only if a root password is defined for MySQL. Enter the password when prompted.
$ mysql --user=user_name --password=your_password db_name
mysql> call stored_procedure_name();
or
$ mysql --user=user_name --password=your_password db_name < script.sql
where script.sql
contains your sql statement:
call stored_procedure_name();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With