25

I can not create a connection to a MySQL database in a vagrant machine with PhpStorm.

My settings are:

DATABASE tab:
- Host: 127.0.0.1
- Port: 3306
- User: root
- Password: root_passsword

SSH/SSL tab:
- Proxy host: 192.168.56.102
- Port: 22
- Proxy user: vagrant
- Proxy password: vagrant

Can someone help me? Thanks

LazyOne
  • 158,824
  • 45
  • 388
  • 391
gnardell
  • 321
  • 2
  • 4
  • 8
  • 2
    From [this tutorial for Vagrant](https://confluence.jetbrains.com/display/PhpStorm/Working+with+Advanced+Vagrant+features+in+PhpStorm#WorkingwithAdvancedVagrantfeaturesinPhpStorm-1.2.Provideconnectioninformation) -- please try `127.0.0.1` and `2222` in your SSH/SSL tab. – LazyOne Jun 14 '15 at 14:03

3 Answers3

33

In SSH/SSL tab, select Auth type Key pair, then copy the path to private key file define in IdentityFile. For instance C:/virtualM/deb56/puphpet/files/dot/ssh/id_rsa

$vagrant up
$vagrant ssh-config
Host local
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "C:/virtualM/deb56/puphpet/files/dot/ssh/id_rsa"
  IdentityFile "C:/Users/User/.vagrant.d/insecure_private_key"
  IdentitiesOnly yes
  LogLevel FATAL
oussaka
  • 930
  • 9
  • 11
  • 7
    thanks, the `vagrant ssh-config` command helped me find which key to use in phpStorm. – mfink Apr 17 '16 at 20:49
22

Here is a really nice article on this subject:

https://www.theodo.fr/blog/2017/03/how-to-manipulate-the-mysql-database-of-your-vagrant-from-phpstorm/

That is:

  1. In PhpStorm click on View -> Tool Windows -> Database
  2. Click on the Database sidebar, click on new -> Datasource -> MySQL The configuration window will appear
  3. Open your terminal.
  4. Go to your project: cd ~/path/to/your/project
  5. Run vagrant ssh-config command from the terminal
  6. At PhpStorm configuration window for connection you are creating go to SSH/SSL tab
  7. Select "Use SSH tunnel" and enter data from the terminal. Auth type should be "Key pair (Open SSH)".
  8. Copy "Host name" to "Proxy host", "Port" to "port", "User" to "Proxy user" and "Identity file" to "Private key file"
  9. At "General" tab you should enter your database connection data as you would on virtual machine (i.e. copy from your project DB settings).
  10. Test your connection.

Or just visit the page which URL I posted at top.

MilanG
  • 6,994
  • 2
  • 35
  • 64
2

If you're using Homestead, these settings worked just fine for my Vagrant box:

Host: 192.168.10.10
Port: 3306
Username: homestead
Password: secret

Then again, so did MilanG's answer, so pick whatever you feel comfortable with. Since it's just local for me I did this and then I won't have to update my keyfile path should I move my Vagrant box. But that's really minor so do whatever you feel is best.

Wotuu
  • 828
  • 1
  • 8
  • 18