Edit this page | Blame

Cannot Connect to MariaDB

Description

GeneNetwork3 is failing to connect to mariadb with the error:

⋮
2024-11-05 14:49:00 Traceback (most recent call last):
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
2024-11-05 14:49:00     rv = self.dispatch_request()
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
2024-11-05 14:49:00     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/gn3/api/menu.py", line 13, in generate_json
2024-11-05 14:49:00     with database_connection(current_app.config["SQL_URI"], logger=current_app.logger) as conn:
2024-11-05 14:49:00   File "/gnu/store/lzw93sik90d780n09svjx5la1bb8g3df-python-3.10.7/lib/python3.10/contextlib.py", line 135, in __enter__
2024-11-05 14:49:00     return next(self.gen)
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/gn3/db_utils.py", line 34, in database_connection
2024-11-05 14:49:00     connection = mdb.connect(db=db_name,
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/MySQLdb/__init__.py", line 121, in Connect
2024-11-05 14:49:00     return Connection(*args, **kwargs)
2024-11-05 14:49:00   File "/gnu/store/83v79izrqn36nbn0l1msbcxa126v21nz-profile/lib/python3.10/site-packages/MySQLdb/connections.py", line 195, in __init__
2024-11-05 14:49:00     super().__init__(*args, **kwargs2)
2024-11-05 14:49:00 MySQLdb.OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

We have previously defined the default socket file[^1][^2] as "/run/mysqld/mysqld.sock".

Troubleshooting Log

I attempted to just bind `/run/mysqld/mysqld.sock` to `/tmp/mysql.sock` by adding the following mapping in GN3's `gunicorn-app` definition:

(file-system-mapping
 (source "/run/mysqld/mysqld.sock")
 (target "/tmp/mysql.sock")
 (writable? #t))

but that does not fix things.

I had tried to change the mysql URI to use IP addresses, i.e.

SQL_URI="mysql://webqtlout:webqtlout@128.169.5.119:3306/db_webqtl"

but that simply changes the error from the above to the one below:

2024-11-05 15:27:12 MySQLdb.OperationalError: (2002, "Can't connect to MySQL server on '128.169.5.119' (115)")

I tried with both `127.0.0.1` and `128.169.5.119`.

My hail-mary was to attempt to expose the `my.cnf` file generated by the `mysql-service-type` definition to the "pola-wrapper", but that is proving tricky, seeing as the file is generated elsewhere[^4] and we do not have a way of figuring out the actual final path of the file.

I tried:

(file-system-mapping
 (source (mixed-text-file "my.cnf"
                          (string-append "[client]\n"
                                         "socket=/run/mysqld/mysqld.sock")))
 (target "/etc/mysql/my.cnf"))

but that did not work either.

Footnotes

[^1] Lines 47 to 49 of https://git.genenetwork.org/gn-machines/tree/production.scm?id=46a1c4c8d01198799e6ac3b99998dca40d2c7094#n47 [^2] Guix's mysql-service-type configurations https://guix.gnu.org/manual/en/html_node/Database-Services.html#index-mysql_002dconfiguration [^3] https://mariadb.com/kb/en/server-system-variables/#socket [^4] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/databases.scm?id=4c56d0cccdc44e12484b26332715f54768738c5f#n576

(made with skribilo)