<p>After further investigation Yii handles the <code>DELIMITER ;;</code> in the <code>createCommand()</code> method. I just had to remove the opening and closing DELIMITER syntax and execute the <code>Craft::$app-&gt;getDb()-&gt;createCommand("CREATE PROCEDURE ( ... )")-&gt;execute()</code> for it to install.  </p>

CC BY-SA 3.0
2018-02-16T22:40:22.957Z
2018-02-16T22:40:22.957Z
a-am
<p>I am trying to add a MySQL stored procedure to the database on plugin install in Craft 3.  I currently have an install migration calling a function from the safeUp method. In this function I am using <code>Craft::$app-&gt;getDb()-&gt;createCommand(" DELIMITER $$ CREATE PROCEDURE ...")-&gt;execute()</code>. However this does not seem to do the trick.</p>

CC BY-SA 3.0
2018-02-16T19:18:06.967Z
Does the user account Craft is connecting to the database with have [CREATE ROUTINE](https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_create-routine) permissions?  Craft doesn't require them by default.
Brad Bell
CC BY-SA 3.0
2018-02-16T19:19:07.230Z
Also worth mentioning that PostgreSQL has different syntax if you'll be supporting that.
Brad Bell
CC BY-SA 3.0
2018-02-16T19:46:58.687Z
The user does have Create Routine Permissions.  The log says there is a syntax error however I have checked the syntax and tested it via SQLPro and it runs. We will start out with MYSQL support until we can convert sql to PostgreSQL.
a-am
CC BY-SA 3.0
2018-02-16T20:30:38.103Z
It says the syntax error is on the first line with the `DELIMITER $$`.
a-am
<plugin-development><database><craft3><mysql>
Install MySQL stored procedure to database on plugin install in Craft 3
# Install MySQL stored procedure to database on plugin install in Craft 3

(Asked by: username_0 on 2018-02-16)

I am trying to add a MySQL stored procedure to the database on plugin install in Craft 3. I currently have an install migration calling a function from the safeUp method. In this function I am using `Craft::$app->getDb()->createCommand(" DELIMITER $$ CREATE PROCEDURE ...")->execute()`. However this does not seem to do the trick.

**Tags:** plugin-development, database, craft3, mysql

> **Comments:**
> **username_1**: Does the user account Craft is connecting to the database with have [CREATE ROUTINE](https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_create-routine) permissions?  Craft doesn't require them by default.  
> **username_1**: Also worth mentioning that PostgreSQL has different syntax if you'll be supporting that.  
> **username_0**: The user does have Create Routine Permissions.  The log says there is a syntax error however I have checked the syntax and tested it via SQLPro and it runs. We will start out with MYSQL support until we can convert sql to PostgreSQL.  
> **username_0**: It says the syntax error is on the first line with the `DELIMITER $$`.  

---

## 1 answers

### Answer by username_0 on 2018-02-16. Score: 1 | Accepted answer

After further investigation Yii handles the `DELIMITER ;;` in the `createCommand()` method. I just had to remove the opening and closing DELIMITER syntax and execute the `Craft::$app->getDb()->createCommand("CREATE PROCEDURE ( ... )")->execute()` for it to install.


---

