Cómo conectarse al servidor Mysql dentro de VirtualBox Vagrant?


Monté una nueva máquina VirtualBox con Vagrant, y dentro de esa VM instalé Mysql Server. ¿Cómo puedo conectarme a ese servidor fuera de la vm? Ya reenvío el puerto 3306 del Vagrantfile, pero cuando intento conectarme al servidor mysql, es resposts con el error: "lectura del paquete de comunicación inicial"

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Author: HNygard, 2012-05-23

7 answers

Asegúrese de que MySQL se vincule a 0.0.0.0 y no a 127.0.0.1 o no será accesible desde fuera de la máquina

Puede asegurarse de esto editando su my.archivo conf y buscando el elemento bind-address want quiere que se vea como bind-address = 0.0.0.0. Luego guarde esto y reinicie mysql:

sudo service mysql restart

Si está haciendo esto en un servidor de producción, debe estar al tanto de las implicaciones de seguridad, discutidas aquí: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0

 123
Author: Dror Bereznitsky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-13 12:13:47

Inicie sesión en su casilla con ssh [email protected] -p 2222 (password vagrant)

Luego: sudo nano /etc/mysql/my.cnf y comenta las siguientes líneas con #

#skip-external-locking 
#bind-address

Guárdelo y salga

Entonces: sudo service mysql restart

Entonces puede conectarse a través de SSH a su servidor MySQL.

 47
Author: Youri van den Bogert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-24 23:44:48

Para cualquiera que intente hacer esto usando mysql workbench o sequel pro estas son las entradas:

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)

Fuente: https://coderwall.com/p/yzwqvg

 17
Author: Sarmen B.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-15 00:48:38

Me encontré con este tema recientemente. Usé PuPHPet para generar una configuración.

Para conectarme a MySQL a través de SSH, la contraseña "vagrant" no funcionaba para mí, en cambio tuve que autenticarme a través del archivo de clave SSH.

Para conectarse con MySQL Workbench

Método de conexión

TCP/IP estándar sobre 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)

Pruebe la conexión.

 17
Author: radiohub,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-17 23:18:18

Bueno, ya que ninguna de las respuestas dadas me ayudó, tuve que buscar más, y encontré solución en este artículo.

Y la respuesta en pocas palabras es la siguiente:

Conexión a MySQL usando 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)>

Usando un enfoque dado, pude conectarme a la base de datos mysql en vagrant desde la máquina host Ubuntu usando MySQL Workbench y también usando Valentina Studio.

 12
Author: WallTearer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-13 11:56:29

Esto funcionó para mí: Conectar a MySQL en 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
 1
Author: DannyFeliz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-16 03:16:18

Estos son los pasos que funcionaron para mí después de iniciar sesión en la caja:

Localice el archivo de configuración de MySQL:

$ 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

En Ubuntu 16, la ruta es típicamente /etc/mysql/mysql.conf.d/mysqld.cnf

Cambiar el archivo de configuración para bind-address:

Si existe, cambie el valor de la siguiente manera. Si no existe, agréguelo en cualquier lugar de la sección [mysqld].

bind-address = 0.0.0.0

Guarde los cambios en el archivo de configuración y reinicie el servicio MySQL.

service mysql restart

Crear / Conceder acceso al usuario de la base de datos:

Conéctese a la base de datos MySQL como usuario root y ejecute los siguientes comandos SQL:

mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';

mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'%';
 1
Author: Raj Mishra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-05 05:58:17