# Problem connecting mysql with rasa x using docker-compose in custom actions

**URL:** <https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963>\
**Category:** \[Deprecated\] Rasa X Community Edition\
**Created:** [August 17, 2021, 11:52am UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963 "2021-08-17T11:52:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 17, 2021, 11:52am UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/1 "2021-08-17T11:52:46Z")

</div>

Hello, I recently deployed rasa x with docker compose the problem is that in my custom actions i have some mysql request (retrieve some data on local database) when i run the `docker-compose up -d` i am able to talk to the bot and run the custom actions, but the connection to the database is not working. Should i declare a mysql part in the docker-compose file ? do you have some examples ?

Thanks @nik202 for he suggestion (maybe if you can help too it would be great)

---

<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 17, 2021, 3:33pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/2 "2021-08-17T15:33:58Z")

</div>

@M_R_LY Hi, are you using mysql image or which sql you are using?

@M_R_LY Or you want to connect a local mysql to docker-compose environment?

@M_R_LY Or you completely want to run rasa, rasa-sdk and mysql in docker-compose environment?

I hope you will answer all the question, so then I can provide you the best help.

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 17, 2021, 4:39pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/3 "2021-08-17T16:39:38Z")

</div>

Hello @nik202Actually am not using any image

@nik202 I have in my linux mysql machine install locally in which there is a rasa\_bot database. When a user talks to the bot, the bot invokes the custom action that is correct for the given intention and searches the rasa database for the answer. This is possible thanks to a configuration file located in the actions folder in which we provide connection information (those of mysql-connector) without docker-compose this works however with docker compose, the connection to the database does not work@nik202 is it possible to connect my local database to the docker environment? on the other hand I do not know if it is necessary to completely run rasa, rasa-sdk and mysql in docker-compose environment

this is the configuration of the dbfile

```
import mysql.connector
import traceback

def getData(query:str):
    """
     @query: sql query that needs to be executed.
     returns the data being executed in "List" format
    """

    try:

        # Setup the connection.
        # Pass your database details here
        mydb = mysql.connector.connect(
            host="10.10.0.15:3306",
            user="toor",
            password="toor",
            database="mydb"
            )

        # set up the cursor to execute the query
        cursor = mydb.cursor()
        cursor.execute(query)

        # fetch all rows from the last executed statement using `fetchall method`.
        results = cursor.fetchall()
        return results
    except:
        print("Error occured while connecting to database or fetching data from database. Error Trace: {}".format(traceback.format_exc()))
        return []

```

@nik202

---

<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 17, 2021, 6:03pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/4 "2021-08-17T18:03:13Z")

</div>

@M_R_LY means your rasa is running on docker and mysql database on local machine right and you want to connect both?

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 17, 2021, 6:33pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/5 "2021-08-17T18:33:47Z")

</div>

@nik202 yeah exactly Or if there is a good practice am in 🙏@nik202

---

<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 17, 2021, 7:43pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/6 "2021-08-17T19:43:24Z")

</div>

@M_R_LYI hope you are aware of the tracker store? try update the endpoints.yml for your current database

```
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
```

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 18, 2021, 8:51am UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/7 "2021-08-18T08:51:35Z")

</div>

hello @nik202  
Actually, this is the section part in the endpoints.yml when you deploy rasa-x via docker compose they are using postgresql ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/a/0/a0eb560796e75163b07b5c2c19d098d57dd96b2d.png)

@nik202 I dont want to store conversation but just retrieve some informations from the local database i have on my actions file somlething like this :

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/1/f/1fe5992abd83a054bf0fe951902de136147c1052.png)

---

<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 18, 2021, 9:17am UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/8 "2021-08-18T09:17:33Z")

</div>

@M_R_LY Please be clear what you using MySQL or Postgres, as you shown in the code you using 3306 which is the port of Mysql and on the other hand, Postgres run on port 5432. I hope you understand my point.

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 18, 2021, 10:24am UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/9 "2021-08-18T10:24:37Z")

</div>

Hi @nik202 i understand your confusion, that configuration in the endpoints.yml has been automatically generated by the [rasa-x docker compose installation](https://rasa.com/docs/rasa-x/installation-and-setup/install/docker-compose#2-install) and its using Postgres for the tracker store. Which have nothing to do with my little configuration that i have in my actions file in order to search for some informations in my database (the second image in my last post).@nik202 there is a part In my my custom actions where i need to connect to my mysql database, search for some data and display it

> [@M\_R\_LY](#):
>
> retrieve some informations from the local database i have on my actions file somlething like this

---

<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 18, 2021, 10:06pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/10 "2021-08-18T22:06:47Z")

</div>

@M_R_LY commented this tracker store and used your ?@M_R_LY please share me the clean and final code of your docker, custom action and endpoints.

---

<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 19, 2021, 5:14pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/11 "2021-08-19T17:14:00Z")

</div>

@M_R_LY No update? huh did you able to solve this?

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 19, 2021, 8:57pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/12 "2021-08-19T20:57:47Z")

</div>

@nik202 hello, not yet. Am travelling right now so soon i get back home i will post the files @nik202

---

<div class="post-metadata">

**Author:** ![siriusraja](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/siriusraja/32/22306_2.png) [@siriusraja](https://forum.rasa.com/u/siriusraja)\
**Post date:** [August 20, 2021, 4:17pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/13 "2021-08-20T16:17:20Z")

</div>

@M_R_LY

I would suggest you containerize your database and bundle it with existing rasa docker set-up. This tutorial guides you on how to containerize your DB and bundle it with an app.

> **[Use containers for development](https://docs.docker.com/language/python/develop/#run-a-database-in-a-container)**
>
> Learn how to develop your application locally.

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 23, 2021, 12:57pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/14 "2021-08-23T12:57:24Z")

</div>

Hello @nik202 sorry for the late i have tryied several configurations but its still the same pb i share with you my :

actions file : [actions.py](https://forum.rasa.com/uploads/short-url/cCgzZoH3CtiLP7PPfO5cH6Zo9uC.py) (3.0 KB)

the endpoints : [endpoints.yml](https://forum.rasa.com/uploads/short-url/mxwPTgrryLoll3tw6cavmFP8UNs.yml) (782 Bytes)

docker-compose.override file : [docker-compose.override.yml](https://forum.rasa.com/uploads/short-url/4GP8TG8JNpQ6afFvOCqbkxen9fO.yml) (448 Bytes)

the docker file : [Dockerfile](https://forum.rasa.com/uploads/short-url/rD6e5JljQmcidVHYZc4UQZBgmEO) (642 Bytes)

for the getData fonction in the actions file, here is the code

> [@M\_R\_LY](#):
>
> configuration of the dbfile

@nik202

---

<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 23, 2021, 1:46pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/15 "2021-08-23T13:46:44Z")

</div>

@M_R_LY I can’t see your rasa or rasa-x only rasa-sdk in docker file? How you managing the rasa? Are you sure you able to run rasa using docker or docker-compose file?

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 23, 2021, 3:59pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/16 "2021-08-23T15:59:02Z")

</div>

hi @nik202 my bad i didnt attach the docker-compose file here it is [docker-compose.yml](https://forum.rasa.com/uploads/short-url/fGeJmLB5Q82tBo2m6j3LWFMSbku.yml) (5.1 KB)

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 23, 2021, 4:27pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/17 "2021-08-23T16:27:57Z")

</div>

@siriusraja if it can help too

---

<div class="post-metadata">

**Author:** ![M\_R\_LY](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m_r_ly/32/11754_2.png) [@M\_R\_LY](https://forum.rasa.com/u/M_R_LY)\
**Post date:** [August 27, 2021, 1:12pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/18 "2021-08-27T13:12:43Z")

</div>

hi @nik202 and , i managed to solve the problem.

i just had to allow my user to connect from my ip (the container ip) in my local database

`GRANT ALL ON database_name.* to 'database_username'@'192.168.208.10' IDENTIFIED BY 'database_password';`

`FLUSH PRIVILEGES;`

you must specify this too the ip of your database

> [@M\_R\_LY](#):
>
> ` host="10.10.0.15:3306",`

@nik202I managed to run also multiple bot in the same server just follow the download step and for the configuration , change the port number for the

> RASA\_X\_HOST (by default 5002)

the

> RASA\_USER\_APP (by default 5055)

and the

> RASA\_PRODUCTION\_HOST (by default 5005)

**for the second bot (or the others)** Change also the nginx service port  
ports:

```auto
  - "8080:8080" (by default for the first bot ) to "8081:8080" (for the second bot)
      - "443:8443" (by default for the first bot) to "444:8443" (for the second bot)

```

and in the browser specify the port for both bot

@nik202 maybe i will do a thread if i got some time Thanks for the help

---

<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 27, 2021, 2:11pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/19 "2021-08-27T14:11:14Z")

</div>

@M_R_LY Many congratulations 👍 and thanks for sharing the solution for other. Good Luck!

---

<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 27, 2021, 2:11pm UTC](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963/20 "2021-08-27T14:11:59Z")

</div>

@M_R_LY Are your bot is running in the Production mode (Rasa-X)?

[Next page](https://forum.rasa.com/t/problem-connecting-mysql-with-rasa-x-using-docker-compose-in-custom-actions/46963.md?page=2)
