Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with MySQL? #76

Open
kelle opened this issue Jun 27, 2024 · 4 comments
Open

Compatible with MySQL? #76

kelle opened this issue Jun 27, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@kelle
Copy link
Collaborator

kelle commented Jun 27, 2024

@jgagneastro asked:

I'm wondering if is something my group can use to communicate with moca through MySQL, in the docs I see only SQLite examples

@kelle kelle added the question Further information is requested label Jun 27, 2024
@dr-rodriguez
Copy link
Collaborator

Astrodbkit2 at its core uses SQLAlchemy, so any database architecture supported there should work, unless there are specific extensions or alterations.
All that should be needed is to write a connection string to your MySQL database with the appropriate driver and package installed: https://docs.sqlalchemy.org/en/20/core/engines.html#mysql

@jgagneastro
Copy link

jgagneastro commented Jun 27, 2024 via email

@jgagneastro
Copy link

Hey David,

I just tried using the connection string I usually use in mocapy, and got an error message. I tried using mysql+pymysql, or just mysql, and both failed (see below):

(astrodbkit2) Mizar jonathan jonathan $ python
Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 10:07:17) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from astrodbkit2.astrodb import Database
>>> from urllib.parse import quote_plus as urlquote
>>> import os
>>> env_username = os.environ.get('MOCA_USERNAME')
>>> env_password = os.environ.get('MOCA_PASSWORD')
>>> env_dbname = os.environ.get('MOCA_DBNAME')
>>> env_host = os.environ.get('MOCA_HOST')
>>> connection_string='mysql+pymysql://'+env_username+':'+urlquote(env_password)+'@'+env_host+'/'+env_dbname
>>> Database
<class 'astrodbkit2.astrodb.Database'>
>>> db = Database(connection_string)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/astrodbkit2/astrodb.py", line 307, in __init__
    self.session, self.base, self.engine = load_connection(
                                           ^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/astrodbkit2/astrodb.py", line 159, in load_connection
    engine = create_engine(connection_string, connect_args=connection_arguments)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in create_engine
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 599, in create_engine
    dbapi = dbapi_meth(**dbapi_args)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/pymysql.py", line 75, in import_dbapi
    return __import__("pymysql")
           ^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pymysql'
>>> connection_string='mysql://'+env_username+':'+urlquote(env_password)+'@'+env_host+'/'+env_dbname
>>> db = Database(connection_string)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/astrodbkit2/astrodb.py", line 307, in __init__
    self.session, self.base, self.engine = load_connection(
                                           ^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/astrodbkit2/astrodb.py", line 159, in load_connection
    engine = create_engine(connection_string, connect_args=connection_arguments)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in create_engine
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 599, in create_engine
    dbapi = dbapi_meth(**dbapi_args)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3-native/anaconda3/envs/astrodbkit2/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 147, in import_dbapi
    return __import__("MySQLdb")
           ^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'MySQLdb'

It sounds like there may currently be something incompatible with MySQL in the way astrodbkit2 is set up.

@jgagneastro
Copy link

Oh nevermind, I just needed to pip install pymysql (I did not recall having done this with mocapy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants