Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Punksolid's avatar

Can't connect with MariaDB and Laradock

I have a project that in a past computer it ran with MariaDB with laradock, now I'm trying with a new computer with all within laradock, but I can't figure it whats the problem, even with other databases I cant connect, but don't know what changed.

My laravel project .env

#####for maria db using laradock #######
DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=default
DB_USERNAME=root
DB_PASSWORD=root
####################### #######

My .env whitin laradock

### MARIADB ###############################################

MARIADB_VERSION=latest
MARIADB_DATABASE=default
MARIADB_USER=default
MARIADB_PASSWORD=secret
MARIADB_PORT=3306
MARIADB_ROOT_PASSWORD=root
MARIADB_ENTRYPOINT_INITDB=./mariadb/docker-entrypoint-initdb.d

my error when running php artisan migrate:fresh --seed

root@3aba6e1153bc:/var/www/simpligps-api# php artisan migrate:fresh --seed

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:670
    666|         // If an exception occurs when attempting to run a query, we'll format the error
    667|         // message to include the bindings with SQL, which will make this exception a
    668|         // lot more helpful to the developer instead of just the database's errors.
    669|         catch (Exception $e) {
  > 670|             throw new QueryException(
    671|                 $query, $this->prepareBindings($bindings), $e
    672|             );
    673|         }
    674| 

      +48 vendor frames 

Should I do any configuration?

0 likes
10 replies
Dunsti's avatar

is your mariadb-box up and running? (check with docker ps or docker-compose ps)

did you start your docker-environment correctly: docker-compose up -d nginx mariadb ?

bobbybouwmann's avatar

Did you run docker-compose up -d mariadb?

You also need to update your .env and set PMA_DB_ENGINE=mariadb.

Punksolid's avatar

Hi @dunsti thanks for your response.

Yes it is running.

docker-compose ps gives this

           Name                          Command              State                                                          Ports                                                        
----------------------------------------------------------------------------------------------------------------------------------------
laradock_docker-in-docker_1   dockerd-entrypoint.sh           Up      2375/tcp, 2376/tcp                                                                                                  
laradock_mariadb_1            docker-entrypoint.sh mysqld     Up      0.0.0.0:3306->3306/tcp                                                                                              
laradock_nginx_1              /bin/bash /opt/startup.sh       Up      0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:81->81/tcp                                                        
laradock_php-fpm_1            docker-php-entrypoint php-fpm   Up      9000/tcp                                                                                                            
laradock_workspace_1          /sbin/my_init                   Up      0.0.0.0:2222->22/tcp, 0.0.0.0:3000->3000/tcp, 0.0.0.0:3001->3001/tcp, 0.0.0.0:8001->8000/tcp, 0.0.0.0:8080->8080/tcp

Yes I started my environment with docker-compose up -d nginx mariadb

@bobbybouwmann thank you for helping me. Yes I ran docker-compose up -d nginx mariadb exactly. I checked my .env and I have set PMA_DB_ENGINE=mariadb I think I set that trying to debug with some mariadb administrator that exists within laradock but I don't remember which was it.

Dunsti's avatar

@bobbybouwmann do you really need to take care of PMA_DB_ENGINE or only if you really use phpMyAdmin ?

@punksolid to narrow down the error, you could try to ssh into your mariadb-box with docker-compose exec mariadb bash and check from the console, if the database is working.

Punksolid's avatar

@dunsti well docker-compose exec mariadb bash was a good advice, at least now I have some access to the database.

I'm not goot at SQL but I tried this

punksolid@josepc  ~/projects/simpligps/laradock   master ●  docker-compose exec mariadb bash
root@37c9bd880be2:/# mysql --version
mysql  Ver 15.1 Distrib 10.4.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
root@37c9bd880be2:/# mysql --user=root --password=root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@37c9bd880be2:/# mysql default
ERROR 1049 (42000): Unknown database 'default'
root@37c9bd880be2:/# mysql --user=default --password=secret
ERROR 1045 (28000): Access denied for user 'default'@'localhost' (using password: YES)
root@37c9bd880be2:/# mysql --user=root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.4.12-MariaDB-1:10.4.12+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]> exit
Bye
root@37c9bd880be2:/# mysql mysql  
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.4.12-MariaDB-1:10.4.12+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]> update user set Password=PASSWORD('root') where user='root';
ERROR 1348 (HY000): Column 'Password' is not updatable
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> 

I think now I can search in how to reset things as if it were on my machine, but I still don't understand why I can't access from the workspace

UPDATE:

This is weird, there is no default database

MariaDB [mysql]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [mysql]>

Dunsti's avatar

After Googling for a while, I found this:

try adding this key to your .env

MARIADB_DB_HOST=mariadb

not sure, if it helps, but worth a try!

1 like
Punksolid's avatar

Hi again @dunsti and @bobbybouwmann

Y set PMA_DB_ENGINE=mariadb and executed docker-compose up -d nginx mariadb phpmyadmin bug failed

flag to clean it up.
Creating laradock_mariadb_1          ... done
Creating laradock_docker-in-docker_1 ... done
Creating laradock_workspace_1        ... 
Creating laradock_phpmyadmin_1       ... 
Creating laradock_phpmyadmin_1       ... error

Creating laradock_workspace_1        ... done
04b39e5c8522659385826c7aa43665898af9619e8): Bind for 0.0.0.0:8080 failed: port is already allocated
Creating laradock_php-fpm_1          ... done
Creating laradock_nginx_1            ... done

however I remembered that once showed me the same error as laravel.

I also set

MARIADB_DB_HOST=mariadb

Rebuild the container with docker-compose build mariadb entered the workspace bash and executed artisan migrate and failed again with the same error as before

root@4c4a0c8f0743:/var/www/simpligps-api# php artisan migrate:fresh --seed
   Illuminate\Database\QueryException 
  SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:670

I think its worth mention that I upgraded manually laravel 5.6 to 7.0, I don't think I missed any important step but don't know it any of that its important enough to make it fail now.

Regards

Punksolid's avatar

UPDATE: I opened PHPStorm that has a secction of services, I deleted everything that sound like a mariadb or laradock, then excecuted the installation again and it works, I dont know why it wasnt working nor why I didnt deleted it the first time.

But now it works with mariadb10.4

Thanks

javleds's avatar

Maybe a little late, for some reason laradock is not able to update the mysql/mariadb login info, because it persists the database files as a volume (or physical files into your machine).

Only the first time that you build/run the mysql/mariadb image it will take the parameters set in the .env file.

You have some choices here:

  • Change the volumes directory by modifying your laradock.env file: DATA_PATH_HOST=~/.laradock/data
  • Add the user creation script into laradock/mariadb/docker-entry-point-initdb.d file.
  • Manually create the user and schema into your mysql/mariadb container (use default settings for it).
  • RISKY and NOT RECOMMENDED: Delete the folder ~/.laradock/data which contains all volumes of your containers.

All the choices require to build and up again.

2 likes

Please or to participate in this conversation.