Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests for validating the changes? Yes, the testing was performed for postgres, sqlite and mysql successfully.
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: The pull request title is prefixed with "FEAT" to indicate a new feature.
relevant migration scripts under backend/apps/webui/internal/migrations, so that to support sqlite, postgres and mysql during db schema creation and migration.
007_add_user_last_active_at.py added database_type check, when that type is mysql, use `, while postgres or sqlite, use ".
for 009_add_models.py, 012_add_tools.py, 014_add_files.py, 015_add_functions.py, all the id = pw.TextField(unique=True) is changed to be pw.CharField(max_length=255, unique=True) so that it wouldn't hit limitation in mysql.
017_add_user_oauth_sub.py the oauth_sub is changed to be pw.CharField(max_length=255, null=True, unique=True), so that it wouldn't hit limitation in mysql.
regarding backend/apps/webui/internal/wrappers.py, import MySQLDatabase, added reconnecting logic for it also.
There is new dependency added in backend/requirements.txt, which is mysqlclient==2.2.4. because sqlalchemy relies on it and it's more stable.
Additional Information
To use mysql database, just like using postgres, specify the DATABASE_URL as mysql://username:passwd@host:port/database
Screenshots or Videos
Please refer testing screenshots:
For sqlite:
For postgresql:
For mysql:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/4708
**Author:** [@zy526](https://github.com/zy526)
**Created:** 8/18/2024
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `support-mysql`
---
### 📝 Commits (1)
- [`b171023`](https://github.com/open-webui/open-webui/commit/b171023acbc32c4c77abe77a85c6e58b1d45ad56) feat: support mysql.
### 📊 Changes
**8 files changed** (+50 additions, -10 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/apps/webui/internal/migrations/007_add_user_last_active_at.py` (+23 -4)
📝 `backend/apps/webui/internal/migrations/009_add_models.py` (+1 -1)
📝 `backend/apps/webui/internal/migrations/012_add_tools.py` (+1 -1)
📝 `backend/apps/webui/internal/migrations/014_add_files.py` (+1 -1)
📝 `backend/apps/webui/internal/migrations/015_add_functions.py` (+1 -1)
📝 `backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py` (+1 -1)
📝 `backend/apps/webui/internal/wrappers.py` (+21 -1)
📝 `backend/requirements.txt` (+1 -0)
</details>
### 📄 Description
# Pull Request Checklist
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests for validating the changes? Yes, the testing was performed for postgres, sqlite and mysql successfully.
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Prefix:** The pull request title is prefixed with "FEAT" to indicate a new feature.
# Changelog Entry
### Description
This pull request enhances to support mysql database besides sqlite and postgres. It'll solve the problem or feedback of the below discussions
[How to use MySQL as database not noly sqlite.](https://github.com/open-webui/open-webui/discussions/4544)
[Failed to start with mysql](https://github.com/open-webui/open-webui/discussions/3903)
[Is possible to customize the OpenWebUI application database and Chrom](https://github.com/open-webui/open-webui/discussions/4288)
[May I ask if I can use an external MySQL to store data?](https://github.com/open-webui/open-webui/discussions/2529)
### Changed
- relevant migration scripts under backend/apps/webui/internal/migrations, so that to support sqlite, postgres and mysql during db schema creation and migration.
- 007_add_user_last_active_at.py added database_type check, when that type is mysql, use `, while postgres or sqlite, use ".
- for 009_add_models.py, 012_add_tools.py, 014_add_files.py, 015_add_functions.py, all the id = pw.TextField(unique=True) is changed to be pw.CharField(max_length=255, unique=True) so that it wouldn't hit limitation in mysql.
- 017_add_user_oauth_sub.py the oauth_sub is changed to be pw.CharField(max_length=255, null=True, unique=True), so that it wouldn't hit limitation in mysql.
- regarding backend/apps/webui/internal/wrappers.py, import MySQLDatabase, added reconnecting logic for it also.
- There is new dependency added in backend/requirements.txt, which is mysqlclient==2.2.4. because sqlalchemy relies on it and it's more stable.
### Additional Information
To use mysql database, just like using postgres, specify the DATABASE_URL as mysql://username:passwd@host:port/database
### Screenshots or Videos
Please refer testing screenshots:
For sqlite:


For postgresql:



For mysql:



---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/4708
Author: @zy526
Created: 8/18/2024
Status: ❌ Closed
Base:
dev← Head:support-mysql📝 Commits (1)
b171023feat: support mysql.📊 Changes
8 files changed (+50 additions, -10 deletions)
View changed files
📝
backend/apps/webui/internal/migrations/007_add_user_last_active_at.py(+23 -4)📝
backend/apps/webui/internal/migrations/009_add_models.py(+1 -1)📝
backend/apps/webui/internal/migrations/012_add_tools.py(+1 -1)📝
backend/apps/webui/internal/migrations/014_add_files.py(+1 -1)📝
backend/apps/webui/internal/migrations/015_add_functions.py(+1 -1)📝
backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py(+1 -1)📝
backend/apps/webui/internal/wrappers.py(+21 -1)📝
backend/requirements.txt(+1 -0)📄 Description
Pull Request Checklist
devbranch.Changelog Entry
Description
This pull request enhances to support mysql database besides sqlite and postgres. It'll solve the problem or feedback of the below discussions
How to use MySQL as database not noly sqlite.
Failed to start with mysql
Is possible to customize the OpenWebUI application database and Chrom
May I ask if I can use an external MySQL to store data?
Changed
Additional Information
To use mysql database, just like using postgres, specify the DATABASE_URL as mysql://username:passwd@host:port/database
Screenshots or Videos
Please refer testing screenshots:
For sqlite:


For postgresql:



For mysql:



🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.