# DB Initialization from volume?

**URL:** <https://forums.percona.com/t/db-initialization-from-volume/16060>\
**Category:** MySQL & MariaDB\
**Tags:** kubernetes\
**Created:** [June 9, 2022, 2:49pm UTC](https://forums.percona.com/t/db-initialization-from-volume/16060 "2022-06-09T14:49:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guymatz-jb](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@guymatz-jb](https://forums.percona.com/u/guymatz-jb)\
**Post date:** [June 9, 2022, 2:49pm UTC](https://forums.percona.com/t/db-initialization-from-volume/16060/1 "2022-06-09T14:49:53Z")

</div>

I see that I can initialize a DB by putting a SQL file in /docker-entrypoint-initdb.d, but _I think_ that means I have to mount a volume there . . . I _think_ an easier way is to have an initContainer put the SQL file on the same volume as the DB, but that requires changing docker-entrypoint.sh to allow for $DATADIR/mysql/some-directory as a dir for SQL files, which requires creating a new, custom, container . . . does this sound like a bad idea? Is there better way? Thanks!!

---

<div class="post-metadata">

**Author:** ![guymatz-jb](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@guymatz-jb](https://forums.percona.com/u/guymatz-jb)\
**Post date:** [June 13, 2022, 4:46pm UTC](https://forums.percona.com/t/db-initialization-from-volume/16060/2 "2022-06-13T16:46:30Z")

</div>

Is my question not clear ☹ ?

---

<div class="post-metadata">

**Author:** ![daniil.bazhenov](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/daniil.bazhenov/32/62_2.png) [@daniil.bazhenov](https://forums.percona.com/u/daniil.bazhenov)\
**Post date:** [June 15, 2022, 11:59am UTC](https://forums.percona.com/t/db-initialization-from-volume/16060/3 "2022-06-15T11:59:34Z")

</div>

Yes, maybe you should give more context and describe what your goal is and what you are doing.

---

<div class="post-metadata">

**Author:** ![guymatz-jb](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@guymatz-jb](https://forums.percona.com/u/guymatz-jb)\
**Post date:** [June 16, 2022, 9:13pm UTC](https://forums.percona.com/t/db-initialization-from-volume/16060/4 "2022-06-16T21:13:56Z")

</div>

Thanks! I would like to initialize a DB on startup of the container . . . I think that functionality already exists, and one can put a sql file in /docker-entrypoint-initdb.d on the container and it will get imported into the DB.

Getting the SQL file in /docker-entrypoint-initdb.d is a bit of a pain for me, though. I would prefer if docker-entrypoint.sh looked for the SQL init file on my PersistentVolume, where my database files will reside.

I have submitted this PR [Added an ENV var to be set to an additional - optional - directory fo… by guymatz · Pull Request #625 · percona/percona-docker · GitHub](https://github.com/percona/percona-docker/pull/625/files)

Is this an anti-pattern? Am I thinking about this the wrong way? Thanks again!!
