[PR #4708] [CLOSED] feat: support mysql. #21541

Closed
opened 2026-04-20 03:34:42 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/4708
Author: @zy526
Created: 8/18/2024
Status: Closed

Base: devHead: support-mysql


📝 Commits (1)

📊 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

  • 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.

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

  • 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:
SQLite1
SQLite2

For postgresql:
Postgresql1
Postgresql2
Postgresql3

For mysql:
MySQL1
MySQL2
MySQL3


🔄 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: ![SQLite1](https://github.com/user-attachments/assets/4e289622-bafe-4c36-9737-4b10641a3e78) ![SQLite2](https://github.com/user-attachments/assets/f2566423-3e6c-49c4-b07e-5604951983e8) For postgresql: ![Postgresql1](https://github.com/user-attachments/assets/c450c560-4093-4a65-bbb2-b52eb5b79835) ![Postgresql2](https://github.com/user-attachments/assets/94b844bf-47b3-4f4c-b737-68ccd5ae7164) ![Postgresql3](https://github.com/user-attachments/assets/d6f2ebe4-6294-4770-a091-bb5481e05d07) For mysql: ![MySQL1](https://github.com/user-attachments/assets/bb26b8ea-ae5d-4ae0-8085-6a53d5409295) ![MySQL2](https://github.com/user-attachments/assets/4bfef448-a081-4dce-87ad-41547af8d7e0) ![MySQL3](https://github.com/user-attachments/assets/1f421455-4eaf-455b-8379-47dc3a3a684e) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 03:34:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#21541