Give MySQL Database Access As Knowledge #905

Closed
opened 2026-02-21 17:28:57 -05:00 by yindo · 9 comments
Owner

Originally created by @MirzaAreebBaig on GitHub (Jan 14, 2024).

Originally assigned to: @JohnJyong, @VincePotato on GitHub.

Self Checks

Description of the new feature / enhancement

Connecting MySql database for knowledge for the knowledge of the AI which as of now is only for documents uploading. I have tried giving data in real time using api but this creates another data of mysql which if user wants to delete any record they have to do it in MySql as well as dify database.

Scenario when this would be used?

This would be a great feature to allow other softwares to integrate seamlessly

Supporting information

No response

Originally created by @MirzaAreebBaig on GitHub (Jan 14, 2024). Originally assigned to: @JohnJyong, @VincePotato on GitHub. ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to file this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). ### Description of the new feature / enhancement Connecting MySql database for knowledge for the knowledge of the AI which as of now is only for documents uploading. I have tried giving data in real time using api but this creates another data of mysql which if user wants to delete any record they have to do it in MySql as well as dify database. ### Scenario when this would be used? This would be a great feature to allow other softwares to integrate seamlessly ### Supporting information _No response_
yindo added the 💪 enhancement👻 feat:rag labels 2026-02-21 17:28:57 -05:00
yindo closed this issue 2026-02-21 17:28:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 14, 2024):

🤖

Hello @MirzaAreebBaig! Welcome 👋. I'm Dosu, a friendly bot here to help out while we wait for a human maintainer. I'm all geared up to assist with bugs, answer your questions, and guide you through contributing to this project. Feel free to poke me anytime. Let's keep things rolling and make this project even more awesome! 🎩🐇

Thank you for your feature request. It's indeed possible to add a feature to dify that allows it to connect to a MySQL database for knowledge. However, the current codebase is set up to use SQLAlchemy with PostgreSQL. To connect to a MySQL database, you would need to modify the database connection string and potentially adjust some of the model definitions to ensure compatibility with MySQL.

Here is an example of how you might modify the database connection in the extensions.ext_database file:

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

def init_app(app):
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://username:password@localhost/dbname'
    db.init_app(app)

In this example, replace 'mysql+pymysql://username:password@localhost/dbname' with your actual MySQL connection string.

Please note that this is a high-level overview and the actual implementation may require additional changes based on the specifics of your MySQL database and the dify application. Also, keep in mind that switching databases may have implications on performance, scaling, and other factors, so it's important to thoroughly test the application after making these changes.

As for your question about whether the dify codebase currently supports any other databases apart from PostgreSQL, based on the provided context, the dify codebase is configured to use PostgreSQL for its database needs. The configuration for the database connection is set up with PostgreSQL details. There is no evidence in the provided context to suggest that any other databases are supported.

However, it's important to note that this doesn't necessarily mean that dify can't support other databases. The underlying technology used for database interactions might support other databases, but additional configuration would be required to use a database other than PostgreSQL.

Without additional context or information, it's not possible to definitively say whether dify supports other databases.

I hope this information is helpful. If you have any further questions or need more clarification, please don't hesitate to ask.

Sources:

-Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot[bot] commented on GitHub (Jan 14, 2024): _🤖_ <!-- Greeting --> Hello @MirzaAreebBaig! Welcome :wave:. I'm [Dosu](https://dosu.dev), a friendly bot here to help out while we wait for a human maintainer. I'm all geared up to assist with bugs, answer your questions, and guide you through contributing to this project. Feel free to poke me anytime. Let's keep things rolling and make this project even more awesome! 🎩🐇 <!-- Answer --> Thank you for your feature request. It's indeed possible to add a feature to dify that allows it to connect to a MySQL database for knowledge. However, the current codebase is set up to use SQLAlchemy with PostgreSQL. To connect to a MySQL database, you would need to modify the database connection string and potentially adjust some of the model definitions to ensure compatibility with MySQL. Here is an example of how you might modify the database connection in the `extensions.ext_database` file: ```python from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def init_app(app): app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://username:password@localhost/dbname' db.init_app(app) ``` In this example, replace `'mysql+pymysql://username:password@localhost/dbname'` with your actual MySQL connection string. Please note that this is a high-level overview and the actual implementation may require additional changes based on the specifics of your MySQL database and the dify application. Also, keep in mind that switching databases may have implications on performance, scaling, and other factors, so it's important to thoroughly test the application after making these changes. As for your question about whether the dify codebase currently supports any other databases apart from PostgreSQL, based on the provided context, the dify codebase is configured to use PostgreSQL for its database needs. The configuration for the database connection is set up with PostgreSQL details. There is no evidence in the provided context to suggest that any other databases are supported. However, it's important to note that this doesn't necessarily mean that dify can't support other databases. The underlying technology used for database interactions might support other databases, but additional configuration would be required to use a database other than PostgreSQL. Without additional context or information, it's not possible to definitively say whether dify supports other databases. I hope this information is helpful. If you have any further questions or need more clarification, please don't hesitate to ask. Sources: - [api/models/dataset.py](https://github.com/langgenius/dify/blob/main/api/models/dataset.py) - [api/config.py](https://github.com/langgenius/dify/blob/main/api/config.py) -[Dosu](https://dosu.dev) ## Sources - [api/models/dataset.py](https://github.com/langgenius/dify/blob/main/api/models/dataset.py) - [api/config.py](https://github.com/langgenius/dify/blob/main/api/config.py) --- This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
Author
Owner

@VincePotato commented on GitHub (Jan 16, 2024):

There is no plan to support this feature for now. Sorry for that.

@VincePotato commented on GitHub (Jan 16, 2024): There is no plan to support this feature for now. Sorry for that.
Author
Owner

@golangpkg commented on GitHub (Jan 26, 2024):

I found the way to support mysql database . because the SQLAlchemy can support both mysql and PG
database . I want to commit a PR .

@golangpkg commented on GitHub (Jan 26, 2024): I found the way to support mysql database . because the SQLAlchemy can support both mysql and PG database . I want to commit a PR .
Author
Owner

@takatost commented on GitHub (Jan 26, 2024):

We've been utilizing some features of PgSQL, like UUID, JSONB type fields. Directly replacing MySQL might lead to some hiccups.

@takatost commented on GitHub (Jan 26, 2024): We've been utilizing some features of PgSQL, like UUID, JSONB type fields. Directly replacing MySQL might lead to some hiccups.
Author
Owner

@takatost commented on GitHub (Jan 26, 2024):

We're gonna roll out the workflow feature in about a month, You'd be able to expand your toolset on your own, and even hook up with MySQL to get the data you need for context.

@takatost commented on GitHub (Jan 26, 2024): We're gonna roll out the workflow feature in about a month, You'd be able to expand your toolset on your own, and even hook up with MySQL to get the data you need for context.
Author
Owner

@golangpkg commented on GitHub (Feb 3, 2024):

We're gonna roll out the workflow feature in about a month, You'd be able to expand your toolset on your own, and even hook up with MySQL to get the data you need for context.

and push this PR:
https://github.com/langgenius/dify/pull/2371/commits/dcb8a04e1f01e5c21875706a8c3678e9b7c7c7ea

use:
default=lambda: uuid.uuid4()
support mysql and postgres db.

@golangpkg commented on GitHub (Feb 3, 2024): > We're gonna roll out the workflow feature in about a month, You'd be able to expand your toolset on your own, and even hook up with MySQL to get the data you need for context. and push this PR: https://github.com/langgenius/dify/pull/2371/commits/dcb8a04e1f01e5c21875706a8c3678e9b7c7c7ea use: default=lambda: uuid.uuid4() support mysql and postgres db.
Author
Owner

@github-actions[bot] commented on GitHub (Feb 18, 2024):

Close due to it's no longer active, if you have any questions, you can reopen it.

@github-actions[bot] commented on GitHub (Feb 18, 2024): Close due to it's no longer active, if you have any questions, you can reopen it.
Author
Owner

@crazywoola commented on GitHub (Feb 21, 2024):

https://github.com/langgenius/dify/pull/2371 Bump

@crazywoola commented on GitHub (Feb 21, 2024): https://github.com/langgenius/dify/pull/2371 Bump
Author
Owner

@github-actions[bot] commented on GitHub (Mar 8, 2024):

Close due to it's no longer active, if you have any questions, you can reopen it.

@github-actions[bot] commented on GitHub (Mar 8, 2024): Close due to it's no longer active, if you have any questions, you can reopen it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#905