Execute MySQL Stored Procedure using Command Line

73,035

Solution 1

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

Solution 2

Or:

mysql --user=your_username --execute="call stored_procedure_name()" db_name

The same as:

mysql ...  -e "call stored_procedure_name()" ...

Solution 3

Or if you don't want to create a .sql file:

$ mysql -u your_username --password=your_password db_name <<!!
call stored_procedure_name();
!!

Solution 4

If you have parameters,

call stored_procedure_name(intValue, doubleValue, 'dateValue');

If your stored procedure doesnot take parameters,

call stored_procedure_name();
Share:
73,035
Maxymus
Author by

Maxymus

Updated on July 05, 2022

Comments

  • Maxymus
    Maxymus almost 2 years

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

  • Code Abominator
    Code Abominator about 6 years
    This also allows you to type/paste in your password rather than leaving it in the command history. Just add -p or --password but don't put the password on the command line, you'll get prompted for it. (also saves escaping the password if it's a nasty random one)