[GH-ISSUE #293] MySQL Connect Issues #236

Closed
opened 2026-02-25 21:31:30 +03:00 by kerem · 6 comments
Owner

Originally created by @doughnet on GitHub (Feb 1, 2021).
Original GitHub issue: https://github.com/ciur/papermerge/issues/293

Originally assigned to: @ciur on GitHub.

Using Ubuntu 20.04 (LXC VM)

Papermerge works fine with SQLite as the backend database but when changing the configuration to MySQL/MariaDB it doesn't connect.

papermerge.conf.py
DBTYPE = "mysql"
DBUSER = "pm"
DBHOST = "localhost"
DBNAME = "pm"
DBPORT = "3306"
DBPASS = "pm"

Error when trying to migrate:

Traceback (most recent call last):
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 3306?
received invalid response to SSL negotiation: j


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 24, in <module>
    execute_from_command_line(sys.argv)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations
    if self.has_table():
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 260, in cursor
    return self._cursor()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 236, in _cursor
    self.ensure_connection()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 3306?
received invalid response to SSL negotiation: j
  • I've tried running via localhost & an external MySQL database to confirm it wasn't a specific issue with the MySQL installation.
  • I've confirmed being able to access both databases/tables with the credentials with mysql client via CLI

Any help would be greatly appreciated!

Originally created by @doughnet on GitHub (Feb 1, 2021). Original GitHub issue: https://github.com/ciur/papermerge/issues/293 Originally assigned to: @ciur on GitHub. Using Ubuntu 20.04 (LXC VM) Papermerge works fine with SQLite as the backend database but when changing the configuration to MySQL/MariaDB it doesn't connect. **papermerge.conf.py** DBTYPE = "mysql" DBUSER = "pm" DBHOST = "localhost" DBNAME = "pm" DBPORT = "3306" DBPASS = "pm" **Error when trying to migrate:** ``` Traceback (most recent call last): File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection self.connect() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect self.connection = self.get_new_connection(conn_params) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection connection = Database.connect(**conn_params) File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 3306? received invalid response to SSL negotiation: j The above exception was the direct cause of the following exception: Traceback (most recent call last): File "./manage.py", line 24, in <module> execute_from_command_line(sys.argv) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute output = self.handle(*args, **options) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 86, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 49, in __init__ self.build_graph() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 212, in build_graph self.applied_migrations = recorder.applied_migrations() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations if self.has_table(): File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 260, in cursor return self._cursor() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 236, in _cursor self.ensure_connection() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection self.connect() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection self.connect() File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect self.connection = self.get_new_connection(conn_params) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/root/papermerge/.venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection connection = Database.connect(**conn_params) File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 3306? received invalid response to SSL negotiation: j ``` - I've tried running via localhost & an external MySQL database to confirm it wasn't a specific issue with the MySQL installation. - I've confirmed being able to access both databases/tables with the credentials with mysql client via CLI Any help would be greatly appreciated!
kerem 2026-02-25 21:31:30 +03:00
Author
Owner

@ciur commented on GitHub (Feb 3, 2021):

I see in provided error messages that Papermerge thinks it deals with PostgreSQL database. It looks like it ignores DBTYPE = "mysql" configuration.

It is definitely not an SSL issue.

Thank you for reporting this issue!

<!-- gh-comment-id:772672937 --> @ciur commented on GitHub (Feb 3, 2021): I see in provided error messages that Papermerge thinks it deals with PostgreSQL database. It looks like it ignores ``DBTYPE = "mysql"`` configuration. It is definitely not an SSL issue. Thank you for reporting this issue!
Author
Owner

@doughnet commented on GitHub (Feb 3, 2021):

Awesome. Thanks for catching. I didn't notice that part of the error.

<!-- gh-comment-id:772687467 --> @doughnet commented on GitHub (Feb 3, 2021): Awesome. Thanks for catching. I didn't notice that part of the error.
Author
Owner

@doughnet commented on GitHub (Feb 5, 2021):

I tried with Postgres and it worked fine. Can't wait for the MySQL fix.

<!-- gh-comment-id:774095015 --> @doughnet commented on GitHub (Feb 5, 2021): I tried with Postgres and it worked fine. Can't wait for the MySQL fix.
Author
Owner

@ciur commented on GitHub (Feb 22, 2021):

I cannot reproduce it.

I tried both v1.5.5 and latest development version. It works in both cases.
I tried from fresh new clone:

  1. clone repo
  2. create python virtualenv + install deps
  3. Use papermerge.conf.py with above configurations (with my credentials, obviously :) )
  4. ./manage.py migrate runs migrations without any issue.

Are you using it from within docker container ?
Can you please describe the steps you followed to install Papermerge ?

<!-- gh-comment-id:783357425 --> @ciur commented on GitHub (Feb 22, 2021): I cannot reproduce it. I tried both v1.5.5 and latest development version. It works in both cases. I tried from fresh new clone: 1. clone repo 2. create python virtualenv + install deps 3. Use papermerge.conf.py with above configurations (with my credentials, obviously :) ) 4. ``./manage.py migrate`` runs migrations without any issue. Are you using it from within docker container ? Can you please describe the steps you followed to install Papermerge ?
Author
Owner

@ciur commented on GitHub (Feb 22, 2021):

However, I received exactly same error (received invalid response to SSL negotiation:...), when I switched back postgres i.e. DBTYPE="pg' BUT by mistake left DBPORT="3306" i.e. mysql port. Maybe you can check if your sql db port number is correct.

<!-- gh-comment-id:783370241 --> @ciur commented on GitHub (Feb 22, 2021): However, I received exactly same error (``received invalid response to SSL negotiation:...``), when I switched back postgres i.e. ``DBTYPE="pg'`` BUT by mistake left ``DBPORT="3306"`` i.e. mysql port. Maybe you can check if your sql db port number is correct.
Author
Owner

@firmicus commented on GitHub (Nov 23, 2021):

@ciur : request to reopen this .... still an issue: can't connect to mysql/mariadb

<!-- gh-comment-id:976474731 --> @firmicus commented on GitHub (Nov 23, 2021): @ciur : request to reopen this .... still an issue: can't connect to mysql/mariadb
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/papermerge#236
No description provided.