Skip to content

mysql/mariadb template does not work out the box - incorrect socket path #2521

Closed
@jefft

Description

@jefft

What happened?

First, thanks for creating devbox! It's already a useful project with amazing potential.

I'm trying to get MySQL running, and although the database runs, the template experience is a bit sad.

There are two technically distinct problems, whose fixes overlap, so I'm describing them both in this bug. I'll link a PR too.

Missing password in test_db_setup command

If I run:

cd /tmp
devbox create mysqltest --template mysql
cd mysqltest
devbox run test_db_setup

the final output is:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Error: error running script "test_db_setup" in Devbox: exit status 1

For reference, here is devbox.json:

{
  "packages": [
    "mysql80@latest"
  ],
  "shell": {
    "init_hook": [],
    "scripts": {
      "connect_db": [
        "mysql -u devbox_user -p -D devbox_lamp"
      ],
      "test_db_setup": [
        "mkdir -p /tmp/devbox/mariadb/run",
        "export MYSQL_UNIX_PORT=/tmp/devbox/mariadb/run/mysql.sock",
        "devbox services up -b",
        "sleep 5",
        "mysql -u root < setup_db.sql",
        "devbox services stop"
      ]
    }
  }
}

The problem with test_db_setup is on the line:

mysql -u root < setup_db.sql

It should be:

mysql -u root --password='' < setup_db.sql

because although the root password is blank, it still needs to be specified.

At least, it is my experience (in this script and in a devbox shell) that --password='' (or just -p) needs to be given. It must have worked for the original author without --password=''. I don't know why. Perhaps it's because I'm running as non-root? Perhaps mysqld initialize-insecure changed? Anyway.

Problem 2: too-long socket file paths

Yes, I read the README, but let's spell it out:

Say I try to run MySQL in a shell, rather than through test_db_setup:

cd /tmp/mysqltest   # Created above with 'devbox create mysqltest --template mysql'
devbox services up -b
devbox shell
mysql -u root -p

This works for me.

But if I have the same project in a longer path:

cd ~/src/github.com/jetify-com/devbox/examples/databases/mysql    # source from git
devbox shell
devbox services up -b

mysqld fails with:

...
[mysql_logs     ] 2025-02-17T04:15:07.646616Z 0 [ERROR] [MY-010267] [Server] The socket file path is too long (> 107): /home/jturner/src/github.com/jetify-com/devbox/examples/databases/mysql/.devbox/virtenv/mysql80/run/mysql.sock
[mysql_logs     ] 2025-02-17T04:15:07.646655Z 0 [ERROR] [MY-010119] [Server] Aborting
[mysql_logs     ] 2025-02-17T04:15:08.686569Z 0 [System] [MY-010910] [Server] /home/jturner/src/github.com/jetify-com/devbox/examples/databases/mysql/.devbox/nix/profile/default/bin/mysqld: Shutdown complete (mysqld 8.0.36)  Source distribution.

The problem is that MYSQL_UNIX_PORT is too long, as the README notes, and the fix is to define MYSQL_UNIX_PORT in an env section, as the README notes:

   env": {
     "MYSQL_UNIX_PORT": "/tmp/devbox/mariadb/run/mysql.sock"
   },

So why not just do it in the example app's devbox.json? Every real project is going to have to change MYSQL_UNIX_PORT in this way, because having one's app break depending on where it runs is ridiculous, so surely the 'template' should? I mean, MYSQL_UNIX_PORT is already hardcoded in test_db_setup - just needs to become an env variable:

{
  "packages": [
    "mysql80@latest"
  ],
  "shell": {
    "init_hook": [],
    "scripts": {
      "connect_db": [
        "mysql -u devbox_user -p -D devbox_lamp"
      ],
      "test_db_setup": [
        "mkdir -p /tmp/devbox/mariadb/run",
        "devbox services up -b",
        "sleep 5",
        "mysql -u root --password='' < setup_db.sql",
        "devbox services stop"
      ]
    }
  },
  "env": {
    "MYSQL_UNIX_PORT": "/tmp/devbox/mariadb/run/mysql.sock"
   }
}

With these changes, this works:

devbox services up -b
devbox shell
mysql -u root --password=''

as does:

devbox run test_db_setup

Steps to reproduce

cd /tmp
devbox create mysqltest --template mysql
cd mysqltest
devbox run test_db_setup

Command

No response

devbox.json

From https://github.com/jetify-com/devbox/blob/main/examples/databases/mysql/devbox.json, i.e.:


{
  "packages": [
    "mysql80@latest"
  ],
  "shell": {
    "init_hook": [],
    "scripts": {
      "connect_db": [
        "mysql -u devbox_user -p -D devbox_lamp"
      ],
      "test_db_setup": [
        "mkdir -p /tmp/devbox/mariadb/run",
        "export MYSQL_UNIX_PORT=/tmp/devbox/mariadb/run/mysql.sock",
        "devbox services up -b",
        "sleep 5",
        "mysql -u root < setup_db.sql",
        "devbox services stop"
      ]
    }
  }
}

Devbox version

0.14.0

Nix version

nix (Nix) 2.18.5

What system does this bug occur on?

Linux (x86-64)

Debug logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssue needs triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions