Pregunta

He montado una nueva Máquina de VirtualBox con Vagrant, y dentro de esa VM he instalado Mysql Server.¿Cómo me puedo conectar a ese servidor fuera de la vm?Ya me adelante el puerto 3306 de la Vagrantfile , pero cuando intento conectar con el servidor mysql, es resposts con el error:de la lectura inicial de los paquetes de comunicación'

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
¿Fue útil?

Solución

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

Usted puede asegurarse de esto por la edición de su mi.conf archivo y buscando la bind-address elemento: quieres ver como bind-address = 0.0.0.0.A continuación, guarde este y reiniciar mysql:

sudo service mysql restart

Si usted está haciendo esto en un servidor de producción, quieres ser conscientes de las implicaciones de seguridad, que se discuten aquí: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0

Otros consejos

Inicie sesión en su caja con ssh vagrant@127.0.0.1 -p 2222 (la contraseña vagrant)

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

#skip-external-locking 
#bind-address

guardar y salir

entonces: sudo service mysql restart

A continuación, puede conectarse a través de SSH a tu servidor MySQL.

Me encontré con este problema recientemente.Utilicé Puphpet para generar una configuración.

Para conectarse a MySQL a través de SSH, la contraseña "Vagrant" no funcionaba para mí, en lugar de eso, 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)

prueba la conexión.

Para cualquier persona que intenta hacer esto usando MySQL Workbench o Secuel 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

Bueno, ya que ninguna de las respuestas dadas me ayudó, tuve que lucir más y encontré una 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 el enfoque dado, pude conectarme a la base de datos MySQL en Vagrant de la máquina del host Ubuntu usando MySQL Workbench y también usando Valentina Studio.

Aquí están los pasos que me funcionaron después de iniciar sesión en el cuadro:

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 suele ser generalmente /etc/mysql/mysql.conf.d/mysqld.cnf

Cambiar archivo de configuración para la dirección de enlace:

Si existe, cambie el valor de la siguiente manera.Si no existe, agregue cualquier parte de la sección [MySQLDL].

bind-address = 0.0.0.0

Guarde sus cambios en el archivo de configuración y reinicie el servicio MYSQL.

service mysql restart

Crear / Grant acceso a usuario de la base de datos:

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

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

mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'%';

Esto funcionó para mí: Conecte 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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top