# Rasa with MySQL Database

**URL:** <https://forum.rasa.com/t/rasa-with-mysql-database/47177>\
**Category:** Rasa Open Source\
**Created:** [August 24, 2021, 10:14pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177 "2021-08-24T22:14:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristianccq](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/cristianccq/32/11599_2.png) [@cristianccq](https://forum.rasa.com/u/cristianccq)\
**Post date:** [August 24, 2021, 10:14pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/1 "2021-08-24T22:14:20Z")

</div>

Hi! I run rasa on the server with MySQL Database and everything is fine, but when I not contact with bot for 8 hours and then write a message - an error occurs.

2021-08-22 17:19:11 ERROR rasa.core.tracker\_store - Error happened when trying to save conversation tracker to ‘SQLTrackerStore’. Falling back to use the ‘InMemoryTrackerStore’. Please investigate the following error: (pymysql.err.OperationalError) (2006, “MySQL server has gone away (BrokenPipeError(32, ‘Broken pipe’))”) [SQL: INSERT INTO events (sender\_id, data) VALUES (%(sender\_id)s, %(data)s)] [parameters: {‘sender\_id’: ‘761f83a0a14f4198807cbc303eab8be2’, ‘data’: ‘{“sender\_id”: “761f83a0a14f4198807cbc303eab8be2”, “event”: “action”, “timestamp”: 1629670751.6087387, “name”: “action\_session\_start”, “policy”: null, “confidence”: 1.0, “action\_text”: null, “hide\_rule\_turn”: false}’}] (Background on this error at: [http://sqlalche.me/e/13/e3q8](http://sqlalche.me/e/13/e3q8)).

I find solution in sqlalchemy on create\_engine, need add two parameters, use pool\_pre\_ping and pool\_recycle .

```auto
# Example
import sqlalchemy
connect_string = dialect + '://{}:{}@{}:{}/{}?charset=utf8mb4'.format(user, passwd, host, port, db)
engine = sqlalchemy.create_engine(connect_string,pool_size=50,pool_recycle=3600,pool_pre_ping=True)

```

The problem is that SQLTrackerStore not receive parameters when dialect is MySQL only if dialect is postgresql

> <https://github.com/RasaHQ/rasa/blob/main/rasa/core/tracker_store.py#L695>

How set this config parameters and avoid connection lost?

[Tracker Stores](https://rasa.com/docs/rasa/tracker-stores/#compatible-databases) , Why MySQL is not official support by RASA?

Thanks.

---

<div class="post-metadata">

**Author:** ![Horizon733](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/horizon733/32/20855_2.png) [@Horizon733](https://forum.rasa.com/u/Horizon733)\
**Post date:** [August 25, 2021, 7:08am UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/2 "2021-08-25T07:08:19Z")

</div>

![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/3/6/36a86056d9264c5203590710aab5a1396c3da4a5.png)These are the databases supported right now. About, why MySQL is not supported I will keep that for Rasa team to answer

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 25, 2021, 10:31am UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/3 "2021-08-25T10:31:57Z")

</div>

@Horizon733 MySQL Workbench, MongoDB and Reddis is also supported. I had worked with these PostgreSQL, Oracle, SQLite is default (rasa), MySQL Workbench and MongoDB.

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 25, 2021, 10:37am UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/4 "2021-08-25T10:37:10Z")

</div>

@cristianccq I hope you looking this? or I got you wrong? For storing the bot/user conversation you can use tracker store:

Update this code in **endpoints.yml**

**For Postgres:**

```
tracker_store:
   type: SQL
   dialect: "postgresql" # the dialect used to interact with the db
   url: "localhost" # (optional) host of the sql db, e.g. "localhost"
   db: "chatbot" # path to your db
   username: "postgres" # username used for authentication
   password: "123" # password used for authentication
   # query: # optional dictionary to be added as a query string to the connection URL
   # driver: my-driver

```

**For MySQL:**

```
tracker_store:
   type: SQL
   dialect: "mysql+pymysql" # the dialect used to interact with the db
   url: "localhost" # (optional) host of the sql db, e.g. "localhost"
   db: "rasa" # path to your db
   username: "root" # username used for authentication
   password: "root" # password used for authentication

```

**Note:** You also can need to install psycopg2-binary and pymysql. You will see when it will thrown error.

---

<div class="post-metadata">

**Author:** ![cristianccq](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/cristianccq/32/11599_2.png) [@cristianccq](https://forum.rasa.com/u/cristianccq)\
**Post date:** [August 25, 2021, 1:48pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/5 "2021-08-25T13:48:59Z")

</div>

thanks for answers, my configuration endpoint is

```auto
tracker_store:
  type: SQL
  dialect: "mysql+pymysql" # the dialect used to interact with the db
  url: "192.168.21.76" # (optiona$
  port: 3306
  db: "rasa_core" # path to your db
  username: "root" # username used for authentication
  password: "root"

```

With this configuration after 8 hours I have a connection loss in mysql.

I have no way to set the configuration in sqlalchemy for mysql.

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 25, 2021, 1:51pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/6 "2021-08-25T13:51:20Z")

</div>

@cristianccq please mention whom you replying, mention @ and name of the user/ aliases.@cristianccq are using docker or docker-compose?

---

<div class="post-metadata">

**Author:** ![cristianccq](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/cristianccq/32/11599_2.png) [@cristianccq](https://forum.rasa.com/u/cristianccq)\
**Post date:** [August 25, 2021, 3:08pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/7 "2021-08-25T15:08:12Z")

</div>

thanks for recomendation @nik202

I am in a local development environment, later I will use docker for my MySQL instance together with another Docker Rasa-Core and Docker Rasa-Action-Server

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [August 25, 2021, 3:46pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/8 "2021-08-25T15:46:56Z")

</div>

@cristianccq If the above solution/suggestion solve your issue, I’d like to request please close this thread for others.

@cristianccq If you need any assistance in docker and docker compose environment installation with MySQL do let me know.

---

<div class="post-metadata">

**Author:** ![cristianccq](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/cristianccq/32/11599_2.png) [@cristianccq](https://forum.rasa.com/u/cristianccq)\
**Post date:** [August 25, 2021, 4:08pm UTC](https://forum.rasa.com/t/rasa-with-mysql-database/47177/9 "2021-08-25T16:08:33Z")

</div>

Hi @nik202 , I’m testing for production environment.

As usual production-ready programs need to override these defaults (to fine-tune pools to their needs), most of the different implementations of connection pools provide a similar set of configuration options. The following list shows the most common options with their descriptions:

- `pool_size`: Sets the number of connections that the pool will handle.
- `max_overflow`: Specifies how many exceeding connections (relative to `pool_size`) the pool supports.
- `pool_recycle`: Configures the maximum age (in seconds) of connections in the pool.
- `pool_timeout`: Identifies how many seconds the program will wait before giving up on getting a connection from the pool.

**I need configure this options with MySQL** , only Postgres dialect allows me to configure it in create\_engine ([rasa/tracker\_store.py at main · RasaHQ/rasa · GitHub](https://github.com/RasaHQ/rasa/blob/main/rasa/core/tracker_store.py#L695))
