Trying to switch our production Rails 7.1.3 server from mysql2 to trilogy to connect to two dbs:
- our remote mysql db at
DB_IP_ADDRon a separate DO droplet - our local solid_cache mysql db on our webserver DO droplet at
PRODUCTION_IP_ADDR
Because of the known issue with trilogy not being able to use mysql 8's caching_sha2_password, I've already reverted mysql to use mysql_native_password, on both the remote mysql server and the production (localhost) cache mysql server:
# on DB_IP_ADDR
mysql> ALTER USER 'us'@'PRODUCTION_IP_ADDR' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> FLUSH PRIVILEGES;
# on PRODUCTION_IP_ADDR
mysql> ALTER USER 'us'@'localhost' IDENTIFIED WITH mysql_native_password BY 'cache_password';
mysql> FLUSH PRIVILEGES;
Our config/database.yml
production:
primary:
adapter: trilogy
database: remote_production_db
host: DB_IP_ADDR
username: us
password: password
socket: /var/run/mysqld/mysqld.sock
encoding: utf8
cache:
adapter: trilogy
database: our_solid_cache_db
host: 127.0.0.1
username: us
password: cache_password
socket: /var/run/mysqld/mysqld.sock
endoding: utf8
migrations_paths: "db/cache/migrate"
The local cache db connects fine with trilogy, but the remote db connection fails with
ActiveRecord::DatabaseConnectionError: There is an issue connecting to your database with your username/password, username: us. (ActiveRecord::DatabaseConnectionError)
Please check your database configuration to ensure the username/password are valid.
...
Caused by:
Trilogy::BaseConnectionError: 1045: Access denied for user 'us'@'localhost' (using password: YES) (Trilogy::BaseConnectionError)
I've double-checked the password and it's right: If i switch the database.yml back to adapter: mysql2 without changing anything else, both db connections are OK.
I notice the error message identifies the attempted user connection as 'us'@'localhost', but the request is not coming from localhost, it's coming from PRODUCTION_IP_ADDR.
Is there something special I need for Trilogy to connect to a remote db, or identify a remote user?
localhostin it! But your comment put me on the right track, thanks. :)