Vagrant: open mysql connection to host - mysql

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.

Related

Why can I connect to mysql through ssh -> mysql, but cannot connect through a ssh tunnel, address is bound to localhost(bind-address 127.0.0.1)?

I can connect to the server by ssh (ssh #ssh_user###ssh_host#) and then use mysql -u#db_user# -p#db_password#. Then I can use the mysql command line as usual, but I am trying to setup DBeaver so I have a client interface for it. Is it impossible to do when the bind-address is set to localhost?
SSH tunnel settings
host: #ssh_host#
port: 22
user: #ssh_user#
auth: (key)
SSH tunnel itself works, I tried it with ssh -L 23:#ssh_host#:22 #ssh_user###ssh_host#

Puphpet MySQL Workbench Connection in Vagrant on Cygwin

I am new to programming, and do not have much idea about ports/forwarding/connection etc.
Installed Vagrant, MySQL Workbench, and Cygwin on Windows 8.1, then
Puphpet on Cygwin and created Virtual Machine, for learning.
But, unable to connect to MySQL on Virtual Machine (MySQL Server is on, on Virtual Machine) from Workbench in Windows.
I did not do any change in vagrantfile or config.yaml.
Tried Out:
Changed to bind-address = 0.0.0.0 in my.conf, but no use.
Commented out # bind-address = 127.0.0.1 in my.conf, again
no use.
Note: (I DELETED id_rsa file when it was not properly doing vagrant up
second time. So, gave full path to id_rsa.ppk, for connecting)
Connection Method: Standard (TCP/IP over SSH)
Parameters:
Hostname: 192.168.56.101:8957
SSH Username: vagrant
SSH Password: vagrant
SSH Key File: c:\cygwin64\home\tomy\puphpet\sutfva\puphpet\files\dot\ssh\id_rsa.ppk
MySQl Hostname: 127.0.0.1
Port: 3306
Username: dbuser
Password: 123
Error message:
IO Error [Errno 10061] No Connection could be made because the target
machine actively refused it. Please refer to logs for details
The answer at Vagrant MySQL Access is not clear to me. How to configure port forwarding?
Can you please guide me in simple words, how I can establish connection? Also, how to disconnect, and any security issue.
Thank you very much Juan Treminio and Brian Morton! Both of them gave valuable tips and inputs for me to come to track! In addition, immense thanks to Juan Treminio for his https://puphpet.com which is a huge help to persons like me.
COMPLETE Connection Details:
Choose
Standard TCP/IP over SSH
Parameters (Mostly default values since I did not change it)
SSH Hostname: 192.168.56.101
SSH Username: vagrant
SSH Password: vagrant
SSH Key File: C:\cygwin64\home\tomy\puphpet\sutfva\puphpet\files\dot\ssh\id_rsa
MySQL Hostname: 127.0.0.1
MySQl Server Port: 3306
Username: root
Password: 123
Note: Remember to note down your connection parameters
Hostname: 192.168.56.101:8957
You shouldn't need the port here, you should probably just need to ender 192.168.56.101
To verify which port SQL Server is listening on, you can ssh into the box and run
netstat -lnutp
This will output a list of the currently open and listening ports on the box. If you do not see SQL Server in the list, then it is not currently running and the service will need to be started.

vagrant sequel pro SSH Tunnel remote host can't connect, bad password

I'm new to MySQL and Vagrant and spent several hours trying to set both up. I can connect to MySQL from the command line with:
mysql --host=127.0.0.1 --user=root --password=[my_password]
I'm trying to connect with Sequel Pro and following a couple tutorials have set up Vagrant/MySQL correctly, I believe. I'm trying to connect thru SSH and tried many combinations of username/password. I believe the correct inputs are:
MySQL Host: 127.0.0.1
username: root
password: [my_password]
SSH Host: 127.0.0.1
SSH User: vagrant
SSH Key: insecure_private_key
SSH Port: 2222
however I'm still getting the error "The SSH Tunnel could not authenticate with the remote host. Please check your password and ensure you still have access."
Any help is appreciated, thanks
You need to choose SSH connection type and select the correct private key.
For Vagrant 1.6 and older, the private key is located in ~/.vagrant.d/insecure_private_key. For Vagrant 1.7 and above, the private key is located in .vagrant/machines/[vm_name]/virtualbox/private_key where the Vagrantfile is located.
Try the following configuration and leave everything else blank. (Of course specify MySQL root password if you've set it up.)
MySQL Host: 127.0.0.1
Username: root
Port: 3306
SSH Host: 127.0.0.1
SSH User: vagrant
SSH Key: ~/.vagrant.d/insecure_private_key
SSH Port: 2222
I got the same error and this solved the issue for me.
ssh-add -K ~/.ssh/id_rsa
For me work added my key identity
ssh-add -K ~/.ssh/id_rsa

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!

How to connect to Mysql Server inside VirtualBox Vagrant?

I mounted a new VirtualBox Machine with Vagrant, and inside that VM I installed Mysql Server. How can I connect to that server outside the vm? I already forward the port 3306 of the Vagrantfile , but when I try to connect to the mysql server, it`s resposts with the error:
'reading initial communication packet'
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Make sure MySQL binds to 0.0.0.0 and not 127.0.0.1 or it will not be accessible from outside the machine
You can ensure this by editing the /etc/mysql/my.conf file and looking for the bind-address item--you want it to look like bind-address = 0.0.0.0. Then save this and restart MySQL:
sudo service mysql restart
If you are doing this on a production server, you want to be aware of the security implications, discussed here: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0
Log in to your box with ssh vagrant#127.0.0.1 -p 2222 (password vagrant)
Then: sudo nano /etc/mysql/my.cnf and comment out the following lines with #
#skip-external-locking
#bind-address
save it & exit
then: sudo service mysql restart
Then you can connect through SSH to your MySQL server.
I came across this issue recently. I used PuPHPet to generate a config.
To connect to MySQL through SSH, the "vagrant" password was not working for me, instead I had to authenticate through the SSH key file.
To connect with MySQL Workbench
Connection method
Standard TCP/IP over SSH
SSH
Hostname: 127.0.0.1:2222 (forwarded SSH port)
Username: vagrant
Password: (do not use)
SSH Key File: C:\vagrantpath\puphpet\files\dot\ssh\insecure_private_key
(Locate your insercure_private_key)
MySQL
Server Port: 3306
username: (root, or username)
password: (password)
Test the connection.
For anyone trying to do this using mysql workbench or sequel pro these are the inputs:
Mysql Host: 192.168.56.101 (or ip that you choose for it)
username: root (or mysql username u created)
password: **** (your mysql password)
database: optional
port: optional (unless you chose another port, defaults to 3306)
ssh host: 192.168.56.101 (or ip that you choose for this vm, like above)
ssh user: vagrant (vagrants default username)
ssh password: vagrant (vagrants default password)
ssh port: optional (unless you chose another)
source: https://coderwall.com/p/yzwqvg
Well, since neither of the given replies helped me, I had to look more, and found solution in this article.
And the answer in a nutshell is the following:
Connecting to MySQL using MySQL Workbench
Connection Method: Standard TCP/IP over SSH
SSH Hostname: <Local VM IP Address (set in PuPHPet)>
SSH Username: vagrant (the default username)
SSH Password: vagrant (the default password)
MySQL Hostname: 127.0.0.1
MySQL Server Port: 3306
Username: root
Password: <MySQL Root Password (set in PuPHPet)>
Using given approach I was able to connect to mysql database in vagrant from host Ubuntu machine using MySQL Workbench and also using Valentina Studio.
Here are the steps that worked for me after logging into the box:
Locate MySQL configuration file:
$ mysql --help | grep -A 1 "Default options"
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
On Ubuntu 16, the path is typically /etc/mysql/mysql.conf.d/mysqld.cnf
Change configuration file for bind-address:
If it exists, change the value as follows. If it doesn't exist, add it anywhere in the [mysqld] section.
bind-address = 0.0.0.0
Save your changes to the configuration file and restart the MySQL service.
service mysql restart
Create / Grant access to database user:
Connect to the MySQL database as the root user and run the following SQL commands:
mysql> CREATE USER 'username'#'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'username'#'%';
This worked for me: Connect to MySQL in Vagrant
username: vagrant password: vagrant
sudo apt-get update sudo apt-get install build-essential zlib1g-dev
git-core sqlite3 libsqlite3-dev sudo aptitude install mysql-server
mysql-client
sudo nano /etc/mysql/my.cnf change: bind-address = 0.0.0.0
mysql -u root -p
use mysql GRANT ALL ON *.* to root#'33.33.33.1' IDENTIFIED BY
'jarvis'; FLUSH PRIVILEGES; exit
sudo /etc/init.d/mysql restart
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
#config.vm.boot_mode = :gui
# Assign this VM to a host-only network IP, allowing you to access
it # via the IP. Host-only networks can talk to the host machine as
well as # any other machines on the same network, but cannot be
accessed (through this # network interface) by any external
networks. # config.vm.network :hostonly, "192.168.33.10"
# Assign this VM to a bridged network, allowing you to connect
directly to a # network using the host's network device. This makes
the VM appear as another # physical device on your network. #
config.vm.network :bridged
# Forward a port from the guest to the host, which allows for
outside # computers to access the VM, whereas host only networking
does not. # config.vm.forward_port 80, 8080
config.vm.forward_port 3306, 3306
config.vm.network :hostonly, "33.33.33.10"
end