knubbe's avatar
Level 36

Can't connect to database with db client [08001]

I am using laravel homestead on linux and when I want to connect to database with phpstorm or DBeaver I receive:

[08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Index 5 out of bounds for length 5.

I investigate and find that problem could be with jdbc driver but all of my drivers are up to date. On homestead I use mysql 5.7 and both (phpstrom and DBeaver) are up to date.

0 likes
14 replies
guybrush_threepwood's avatar

Hi,

What IP / port / credentials are you using to connect?

According to the Laravel docs you should use:

Host: 127.0.0.1
Username: homestead
Password: secret
Database: <optional>
Port: 33060

Port 3306 should only be used when connecting to the database from within Homestead.

You could also try setting a SSH tunnel in your client in order to SSH first and then connect locally to MySQL.

knubbe's avatar
Level 36

I am using right credentials. On macOs I setup easily but I can't on linux ubuntu 20.04.

guybrush_threepwood's avatar

This is how I connect to Homestead with DBeaver:

Connection settings

Server host: localhost
Port: 3306
Database: 
Username: root
Password: secret
Local client: /usr/bin

Network

[X] Use SSH tunnel
IP: 192.168.10.10
Port: 22
User Name: vagrant
Authentication method: Password
Password: vagrant
knubbe's avatar
Level 36

why is your username root and port 3306 instead of 33060 and for ssh how you use vagrant for username and password

guybrush_threepwood's avatar

I don't remember, I set it up three years ago.

I believe I'm using root because of some limitation of the homestead account (couldn't list all databases, needed to access theinformation_schema tables, needed to change database configuration options on runtime, I don't know). You're free to use the homestead default credentials.

I'm using port 3306 because I'm connecting to MySQL locally after initiating an SSH tunnel. It's the equivalent to running homestead ssh and then attempting to connect to mysql. Port 33060 is for forwarding the connection from your machine to the VM.

Vagrant username/password is the default SSH credentials for vagrant, on top of which homestead is built.

The important question is: Did it work?

I recently re-installed Virtualbox, Vagrant and Homestead and DBeaver's connection kept working flawlessly with the same ports and credentials I set up years ago.

knubbe's avatar
Level 36

When I use ssh with credentials that you shere I got this: Access denied for user 'root'@'localhost' (using password: NO)

guybrush_threepwood's avatar

Have you set up the conection using using DBeaver or are you trying to access mysql from the command line after connecting via SSH?

It doesn't seem like you're specifying the password (using password: NO).

When you connect to MySQL using the command line you have to add the password option or it automatically fails without even asking for a password:

mysql -u root -p
knubbe's avatar
Level 36

I am trying to setup a connection with DBeaver after I vagrant up. In vagrant I was not able to connect to mysql with root as user from command line. I can connect with mysql -u homestead - p where password is secret

guybrush_threepwood's avatar

I understand. At least if you're seeing that error in DBeaver it means that you're establishing the SSH tunnel correctly.

Can you try swapping DBeaver's connection configuration with the default homestead credentials? (leaving the port as it is)

Server host: localhost
Port: 3306
Database: 
Username: homestead
Password: secret
Local client: /usr/bin
knubbe's avatar
Level 36

Public Key Retrieval is not allowed

guybrush_threepwood's avatar

Try this:

To change the settings on Dbeaver:

1- Right click your connection, choose "Edit Connection"

2- On the "Connection settings" screen (main screen) click on "Edit Driver Settings"

3- Click on "Connection properties"

4- Right click the "user properties" area and choose "Add new property"

5- Add two properties: "useSSL" and "allowPublicKeyRetrieval"

6- Set their values to "false" and "true" by double clicking on the "value" column

Save and re-test the connection.

knubbe's avatar
Level 36

Access denied for user 'homestead'@'localhost' (using password: YES)

knubbe's avatar
knubbe
OP
Best Answer
Level 36

I finally figure out. For homestead on linux you need to pass this credentials:

host: 192.168.10.10

instead of 127.0.0.1 or localhost

2 likes

Please or to participate in this conversation.