Domanda

Ho montato una nuova macchina VirtualBox con Vagrant e all'interno di quella VM ho installato Mysql Server.Come posso connettermi a quel server fuori dalla VM?Inoltro già la porta 3306 del Vagrantfile, ma quando provo a connettermi al server mysql, viene risposto con l'errore:'lettura del pacchetto di comunicazione iniziale'

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
È stato utile?

Soluzione

Assicurati che MySQL si associ a 0.0.0.0 e non a 127.0.0.1 altrimenti non sarà accessibile dall'esterno della macchina

Puoi assicurartelo modificando il tuo file my.conf e cercando il file bind-address oggetto: vuoi che assomigli bind-address = 0.0.0.0.Quindi salva questo e riavvia mysql:

sudo service mysql restart

Se lo stai facendo su un server di produzione, vuoi essere consapevole delle implicazioni sulla sicurezza, discusse qui: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0

Altri suggerimenti

Accedi alla tua scatola con ssh vagrant@127.0.0.1 -p 2222 (Password Vangant)

Quindi: sudo nano /etc/mysql/my.cnf e commentare le seguenti righe con #

#skip-external-locking 
#bind-address
.

Salva e uscita

Allora: sudo service mysql restart

Quindi è possibile connettersi tramite SSH al tuo server MySQL.

Ho trovato di recente questo problema.Ho usato puphpet per generare una configurazione.

Per connettersi a MySQL attraverso SSH, la password "vagabante" non funzionava per me, invece ho dovuto autenticare attraverso il file chiave SSH.

Per connettersi con Workbench MySQL

Metodo di connessione

Standard TCP / IP su 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)
.

Testare la connessione.

Per chiunque tenta di farlo utilizzando MySQL Workbench o Sequel Pro Questi sono gli ingressi:

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)
.

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

Beh, dal momento che nessuna delle risposte indicate mi ha aiutato, ho dovuto guardare di più, e ho trovato una soluzione in Questo articolo .

E la risposta in poche parole è la seguente:

Connessione a MySQL Uso di 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 approccio specificato Sono stato in grado di connettersi al database MySQL in Vagagrant dalla macchina host Ubuntu utilizzando MySQL Workbench e anche usando Valentina Studio.

Qui ci sono i passaggi che hanno funzionato per me dopo aver effettuato l'accesso alla casella:

Individua il file di configurazione 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
.

su Ubuntu 16, il percorso è in genere /etc/mysql/mysql.conf.d/mysqld.cnf

Modifica file di configurazione per Bind-Indirizzo:

Se esiste, cambia il valore come segue.Se non esiste, aggiungilo ovunque nella sezione [MySQLD].

bind-address = 0.0.0.0
.

Salva le modifiche al file di configurazione e riavvia il servizio MySQL.

service mysql restart
.

Crea / concedi l'accesso all'utente del database:

Connetti al database MySQL come utente root ed eseguire i seguenti comandi SQL:

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

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

Questo ha funzionato per me: Connetti a 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
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top