skip to Main Content

I’m confused a little bit about how I can import a custom .sql file into the default db as soon as it gets ready.
I tried putting an import command under .ddev/commands/web but didn’t work out.

Thanks in advance

I’ve added a .sh file under .ddev/commands/web with the following:

mysql -u db -pdb db < /var/www/html/sql/my.sql

If I run the above command when I create the container it works fine but it doesn’t auto load when I make the container for first time.
I’m trying to find a way to load that file after the creation of the container.

2

Answers


  1. Chosen as BEST ANSWER

    Sorry I wasn't clear enough, I meant that I want to be executed the first time that I will run ddev start not afterwards.


  2. The reason why the import command is not working is because the .ddev/commands/web file is only executed when you start your project with the ddev start command. If you want to import the custom .sql file after the container is created, you need to use a different method.

    One way to do this is to use the ddev execcommand. The ddev exec command allows you to run a command inside the container. to import the custom .sql file, you would run the following command:
    ddev exec sh -c 'mysql -u db -pdb db < /var/www/html/sql/my.sql'

    This will run the mysql command inside the container and import the custom .sql file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search