Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute MySQL Stored Procedure using Command Line

Please help me out to execute a MySQL Stored procedure in command line, where the procedure contains conditional statements..

like image 456
Maxymus Avatar asked Sep 30 '10 06:09

Maxymus


People also ask

How do I execute a procedure in MySQL?

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.

How do I run a SQL stored procedure from the command line?

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.

How do you call a procedure in MySQL terminal?

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);

How do I run MySQL from command line?

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.


1 Answers

$ 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();
like image 78
dogbane Avatar answered Sep 19 '22 06:09

dogbane