3
votes

I upgraded laravel/homestead box to version 11.1.0. Then a surprising happened: My DBs disappeared. How? I have no idea. But then when I tried to reinstall the databases using Homestead.yaml, it did not work eventhough I added the list of databases in Homestead.yaml.

Here the what I did in Homestead.yaml:

    databases:
        - db00
        - db01

Then I ran "vagrant provision" but nothing changed in MySQL. "show databases;" displayed default tables only.

Then I activated the features:

     features:
        - mysql: true
        - mariadb: false

Then I ran "vagrant provision" and it worked. I had both databases (db00 and db01) in MySQL. Here are the problems:

  1. Based on laravel/homestead documentation for laravel v8.x, there is no feature option for mysql. That caused the following error during provisioning:

    homestead: Invalid feature: mysql
    homestead: Ignoring feature: mariadb because it is set to false
    
  2. Once I added the option "- mysql" to the Homestead.yaml, I received the following errors for MariaDB

    homestead: Running: script: Creating MySQL / MariaDB Database: db00
    homestead: We didn't find a PID for mariadb, skipping $DB creation
    homestead: Running: script: Creating MySQL / MariaDB Database: db01
    homestead: We didn't find a PID for mariadb, skipping $DB creation
    

Now here my question: What is going on? Without the feature option "- mysql" no database is created; no matter if I define the list under the databases. Once I add it, things work, databases are generated however, I get error that the feature is not valid. Also it is not included in the documentation. Where am I going wrong? or if anyone has an explanation or a better solution?

2

2 Answers

1
votes

The answers to both of your questions is: because the documention is a bit misleading

For your first question, mysql is technically not an optional feature since is installed by default. However, as of v11.3.0 in order to provision custom databases it must be listed under the features section in the Homestead.yaml:

features:
    - mysql: true

due to only running the provisioning script if mysql is specifically enabled:
https://github.com/laravel/homestead/blob/v11.3.0/scripts/homestead.rb

For your second question, the error message is displayed due to the way that the create-mysql.sh script was implemented in v11.0.0:
https://github.com/laravel/homestead/blob/v11.0.0/scripts/create-mysql.sh

if [ -z "$mariadb" ]
then
      # Skip Creating MariaDB database
      echo "We didn't find a PID for mariadb, skipping \$DB creation"
else
      mysql -e "CREATE DATABASE IF NOT EXISTS \`$DB\` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci";
fi

With the configuration you are using the if [ -z "$mariadb" ] condition will always be true because the process id of mariadbd will never be found since it is not enabled. Therefore the We didn't find a PID for mariadb, skipping $DB creation message will always be displayed even though the databases are succesfully created for mysql. Technically that is correct based on the way the script is coded, but it is also a bit confusing.

Also as for why your databases disappeared when upgrading, assuming you were following these instructions:
https://laravel.com/docs/8.x/homestead#updating-homestead

The vagrant destroy command will completely remove the homestead box and rebuild it. Therefore any data or other custom configuration will be lost unless it is configured to backup the data:
https://laravel.com/docs/8.x/homestead#database-backups

0
votes

I ran into this same issue recently with Homestead 12.3.0 and solved it by editing my Homestead.yaml with the following:

...

databases:
    - homestead
    - my_database

features:
    # - mysql: true
    - mariadb: false
    - postgresql: false
    - ohmyzsh: false
    - webdriver: false

services:
    - "mysql"

...

Then I ran vagrant reload --provision, and did not see the MariaDB error anymore.

To confirm you can SSH into the vagrant box, and log into MySQL (homestead / secret). In my case I found the database had been created correctly.