Connect to remote mysql server from localhost docker container - mysql

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?

Related

Cannot access MySQL container in VPS from MySQL Workbench In My PC

I've created a docker container that runs MySQL on it and exposes it on the default port (3306) on a DO droplet (Ubuntu 20).
I tried accessing it on my laptop with the following parameters:
Hostname: (VPS's IP address. I also tried Public Gateway IP)
Connection: Standard (TCP/IP)
Port: 3306
Username: root
Password: (Password I have set while creating the container)
The error message just says "Could not connect to localhost"
Am I missing a step that maybe exposes the container to the internet?
After a couple of hours, I found out that the docker run command has to have -p parameter. -p=3306:3306 in my case.

How to connect to MySQL database in docker container from Vagrant box?

I have a Symfony project which I'm running in 3 docker containers:
A PHP-FPM container
A NginX container
A MySQL container
I have another (Laravel) project which is running through the pre-packaged Vagrant Box setup (Homestead).
I'm now trying to connect to the MySQL database (of the Docker setup) from within the Vagrant box of my Laravel project.
What I know for sure:
I can connect to my MySQL database from my host machine through Sequel Pro.
Host: 127.0.0.1
Port: 3306
What I don't know:
Which host / port should I define in my Laravel project in order to successfully connect to the MySQL database from my docker container setup?
If you can connect from your Workstation in should also work from the VM.
Simply use as connection parameter:
IP: Your Workstation IP
Port: 3306
Important: Publish the port of the Container with : -p 3306:3306

Cannot connect to Database MySQL from workbench

I am try to using MySQL Workbench but its showing error "Cannot connect to database".Neither it taking it localhost or my Endpoint of AWS RDS as DNS in host in workbench.
"I am using Xampp for mysql server running on port number 3306 "
Error :
Cannot connect to DataBase Server
Your connection attemp to failed for user 'root' from host to server at localhost:NULL;
can't open named pipe to host:pipe:MySQL (2)
Please:
1.Check that mysql is running on server localhost.
2.Check that mysql is running on port NULL (note 3306 is the default,but this can be changed)
3.Check the root has rights to connect to localhost from your address .
4.Make sure you are both providing a password if nedded and using the correct password for localhost connecting from the host address you are connecting from.
If you want to test the connection to MySql, Use Heidi (i recommend it). If it didn"t work, check if your DataBase server is running in port 3306 by taping:
netstat -atp tcp | grep -i "listen".
You can also change listenning port in /xampp/mysql/bin/my.ini:
my.ini:
Password = your_password
port = 3306 ---> 3307
socket = "/ xampp / mysql / mysql.sock"``
Looks like you have no port configured. Check your connection settings that you have a port set.

Vagrant: open mysql connection to host

I'd like to use MySql Workbench to browse my database in Vagrant from host machine.
So far I just commented the line bind-address = 127.0.0.1 in my.cnf and all was ok, but recently I connected to a new wi-fi and things seemed to change, I had to change guest ip address from 192.168.0.200 to 192.168.1.200 and I can't open mysql connection from host.
I tryed also to add bind-address = 10.0.2.2 guessing (not sure) this was my host ip but still the same.
What do I need to do?
Thank you
Define a static ip for your box like in this example:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "10.0.0.6"
In Mysql Workbench create a new connection over SSH:
Connection Method: Standard TCP/IP over SSH
SSH Hostname: 10.0.0.6 (like above)
SSH Username: vagrant
SSH password: vagrant
MySQL Hostname: 127.0.0.1
MySQL Username: root
MySQL Password: root
SSH Host Key identification:
Instead of a password you can use the box specific Private Key. You can get the path by executing vagrant ssh-config.

can't access fortrabbit mysql db through terminal (ssh)

I can't access mysql through terminal on fortrabbit. I follow all steps but it is rejecting my password. However I can regullary login through ssh and edit my application. Anyone had that issue ? Thanks.
I have solved this in the past using a SSH tunnel. You open an SSH tunnel to the server, and then you connect to the MySQL server there from the endpoint of that tunnel. As such, to MySQL you appear to be connecting locally.
From the terminal:
First you need to open the tunnel, you can do it like this:
ssh -N -L8889:127.0.0.1:3306 username#your.fortrabbit.domain.com &
This opens port 8889, then opens a tunnel to your.fortrabbit.domain.com, then forwards that local port through the tunnel to the IP 127.0.0.1 and port 3306 relative to the server at your.fortrabbit.domain.com.
The options in more detail:
-N: Do not execute a remote command.
-L: Specifies the ports (local and remote).
8889: Your local port that is being forwarded.
127.0.0.1: the remote IP to which you're forwarding, relative to the server which ssh is connecting to
3306: the remote port to which you're forwarding.
username#your.fortrabbit.domain.com: Your username and domain with fortrabbit.
Now you're ready to open the connection. In the same terminal, use the following command:
mysql -h 127.0.0.1 -P 8889 -u mysql-username -p
port 8889 is now being forwarded to the port and IP of your MySQL server on the fortrabbit side, so just replace mysql-username with your username on the mysql server, and you're connected!
From a GUI:
You mentioned in your comments that you're using Ubuntu, so install MySQL Workbench from the Software Centre or here, create a New Connection and select the connection type as "Standard TCP/IP over SSH".
You will need to configure the following:
SSH Hostname: the hostname or IP of your ssh account with fortrabbit
SSH Username: your username with them
SSH Password: your password with them
SSH Keyfile: If you use keys for authentication, select the private one here.
MySQL Hostname: 127.0.0.1 (because it's local to the endpoint of your tunnel.
MySQL Server Port: normally "3306".
Username: The username for the DB
Password: The password for the DB
Default Schema: Whatever should be the default schema for this DB (can be left blank).
That should then connect from wherever you are!