Moved from (depecrated) mysql_native password type to caching_sha2_password
This commit is contained in:
1 parent
e75057ee1c
commit
ef58bfa6aa
2 files changed
+10
-12
No files matched your search
@@ -126,12 +126,3 @@ Available at `http://localhost:9000/metrics`:
|
|||||||
- `msg_retry_total{queue_name, uuid, retry_count}`: Retry attempts
|
- `msg_retry_total{queue_name, uuid, retry_count}`: Retry attempts
|
||||||
- `msg_failed_total`: Failed deliveries
|
- `msg_failed_total`: Failed deliveries
|
||||||
- `queue_depth{queue_name}`: Current queue message counts
|
- `queue_depth{queue_name}`: Current queue message counts
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Connection Issues
|
|
||||||
- `aiomysql` uses `PyMySQL` which requires the `mysql_native_password` plugin to be used. Can be checked and changed via:
|
|
||||||
```sql
|
|
||||||
SELECT user, host, plugin FROM mysql.user WHERE user='backend-push-notifications';
|
|
||||||
ALTER USER 'backend-push-notifications'@'%' IDENTIFIED WITH mysql_native_password BY 'db_password';
|
|
||||||
```
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
import ssl
|
||||||
|
|
||||||
import aiomysql
|
import aiomysql
|
||||||
import pymysql.err
|
import pymysql.err
|
||||||
@@ -8,13 +9,18 @@ import pymysql.err
|
|||||||
from secret_manager import get_secret
|
from secret_manager import get_secret
|
||||||
from simple_logger_handler import setup_logger
|
from simple_logger_handler import setup_logger
|
||||||
|
|
||||||
db_username = get_secret(os.getenv("DB_USERNAME",""),"/etc/secrets/db_username")
|
db_username = get_secret("DB_USERNAME","/etc/secrets/db_username")
|
||||||
db_password = get_secret(os.getenv("DB_PASSWORD",""),"/etc/secrets/db_password")
|
db_password = get_secret("DB_PASSWORD","/etc/secrets/db_password")
|
||||||
db_host = os.getenv("DB_HOST","localhost")
|
db_host = os.getenv("DB_HOST","localhost")
|
||||||
db_database = os.getenv("DB_DATABASE","app")
|
db_database = os.getenv("DB_DATABASE","app")
|
||||||
|
|
||||||
logger = setup_logger(__name__)
|
logger = setup_logger(__name__)
|
||||||
|
|
||||||
|
#mysql_native is deprecated, caching_sha2_password needs a encrypted connection on first login to work
|
||||||
|
#aiomysql does not create that by default but mysql-connector-python does, so this is the workaround
|
||||||
|
_ssl_ctx = ssl.create_default_context()
|
||||||
|
_ssl_ctx.check_hostname = False
|
||||||
|
_ssl_ctx.verify_mode = ssl.CERT_NONE
|
||||||
|
|
||||||
class DBManager:
|
class DBManager:
|
||||||
def __init__(self, host, user, password, db, port=3306, pool_size=5, health_interval=60):
|
def __init__(self, host, user, password, db, port=3306, pool_size=5, health_interval=60):
|
||||||
@@ -40,7 +46,8 @@ class DBManager:
|
|||||||
minsize=1,
|
minsize=1,
|
||||||
maxsize=self.pool_size,
|
maxsize=self.pool_size,
|
||||||
autocommit=True,
|
autocommit=True,
|
||||||
cursorclass=aiomysql.DictCursor
|
cursorclass=aiomysql.DictCursor,
|
||||||
|
ssl=_ssl_ctx,
|
||||||
)
|
)
|
||||||
logger.info("[DB] Connection pool created")
|
logger.info("[DB] Connection pool created")
|
||||||
logger.debug(f"[DB] Pool object: {self._pool}")
|
logger.debug(f"[DB] Pool object: {self._pool}")
|
||||||
|
|||||||
Reference in new issue
Block a user