mysql connect to remote database specified by ip and server name - mysql

Trying to connect to a database using the mysql2 gem through a VPN.
I'm connected to the VPN, and can access secure pages via browser. I have the following info:
server: ###-*********
ip: ###.###.##.###
port: ####
username: ********
password: ********
schema: ***********_***
And the gem wants:
username (check)
password (check)
host (?)
port (check)
database (?)
I've tried putting the ip as the host and using schema and server for database, but it won't connect.

Related

Remote Connection to MYSQL from Heroku Rails App

I am having some difficulties for the past few days while trying to connect to a remote MYSQL DB from a Heroku hosted Rails App.
Locally I am able to connect to the remote database and retrieve/modify data.
My database.yml file:
remote:
adapter: mysql2
host: host.address
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
database: databasename
username: username
password: password
port: 3306
Model that I try to use this remote database for:
class Test < ApplicationRecord
establish_connection(:remote)
self.table_name = "tests"
end
The mysql database is hosted on server with Cpanel which has remote database service, where I configure to be accessible from every ip (0.0.0.0), (%), (www.mywebsite.com).
When I try connecting to the database with e.g.: running Test.new via heroku rails console, I get the following:
app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.2.3/lib/active_record/connection_adapters/mysql2_adapter.rb:51:in `rescue in new_client': There is an issue connecting with your hostname: my.host.ip. (ActiveRecord::DatabaseConnectionError)
Please check your database configuration and ensure there is a valid connection to your database.
/app/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:95:in `connect': Can't connect to MySQL server on 'my.host.ip:3306' (110) (Mysql2::Error::ConnectionError)
This is my secondary Database. My production one is postgresql used with the postgresql AddOn on heroku..
All the ENV variables I use in heroku are for the username, pass, database name, host.
I have read all the questions here regarding this and tried everything. Not sure what I am missing.
Thanks for any advice.

Connect to remote mysql server from localhost docker container

I have doctrine config:
doctrine:
dbal:
driver:pdo_mysql
url:"mysql://%database_user%:%database_password%#%database_host%:%database_port%/%database_name%"
Where database_user is root, password is root user password (re-checked), host is my server ip address, port is 3306 and name is my db name.
When I use these from workbench I can connect but from running docker container for php and nginx. And this config, I get connection refused.
Do I need somehow to allow connections from localhost? Why is it working from workbench then?

DataGrip MySql connection timeout - tableplus+cli both work instantly

I am attempting to connect to a MySql DB with DataGrip, but it just endlessly fails due to timeouts.
I have successfully connected near-instantly with both TablePlus and by manually sshing in and using mysql in the cli.
The access arrangement is between my laptop: computer A, a gateway machine: computer B, and the database machine: computer C, in the structure:
A-->B-->C
My credentials are all present and correct and have been checked and reentered, and are as such:
GENERAL
Host: localhost
Port: 3306
User: <username>
Password: <password>
Save: Forever
Database: <database name>
SSH/SSL
Proxy host: C<.url.tld>
Proxy port: 22
Proxy user: <username>
Local port: 3306
Auth type: Key pair (OpenSSH or PuTTY)
Private key file: <path to ssh key>
Passphrase: <password>
Remember: Forever
Also, my ssh config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host B<.url.tld>
ForwardAgent yes
User <username>
Host *<url.tld> !B<url.tld>
ProxyJump B<.url.tld>
User <username>
ForwardAgent yes
The logs simply record
com.intellij.execution.ExecutionException: SSH: Error connecting to remote host C<.url.tld>: Operation timed out (Connection timed out)
with a nice lengthly Java stacktrace of the exact same error over and over again all the way down.
I have tried varying the details in the setup many times and repeatedly got the same error - the only difference is if I deliberately enter my ssh key passphrase incorrectly, it requests it be reentered correctly.
What is going on? How do I fix this and connect to the DB?

Laravel Homestead Cannot Connect to MySQL from host

I saw many threads on forums and Stackoverflow about this issue but none were addressing in a way that worked for me.
I used the following credential on my host computer (using Sequel Pro) to log in homestead MySQL as documented:
host: 127.0.0.1
username: homestead
password: secret
It says that "Unable to connect to host 127.0.0.1, or the request timed out".
I then tried to log using ssh:
MySQL host: 10.0.2.15
Username: homestead
Password: secret
Port: 3306
SSH host: 192.168.10.10
SSH user: vagrant
SSH Password: ~/.ssh/id_rsa
I got "Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords."
I then followed this to change my password.
homestead ssh
mysql -uhomestead -psecret
SET PASSWORD = PASSWORD('secret');
That fixed my problem as I was now able to connect from ssh as described above.

Use Ruby on Rails and SSH to access remote MySQL database on remote server

How do I use SSH to make my RoR db calls to a remote MySQL db on a remote server. I have the host ip, ssh username, ssh password, db, db username, db password, and port. Any examples I have seen show the code just in a ruby script but I do not know how to apply that solution to my web application. Do I need to change anything in my database.yml file? I appreciate any help...
The way to go about this is to create an SSH Tunnel to the destination database host and point the local server to it.
Check out: How do I configure Rails for password-less access to remote database
You can connect to remote databases from Rails. Simply edit your database.yml:
development:
adapter: mysql
encoding: unicode
pool: 5
username: username
password: password
host: hostname
port: port_number
database: database_name