yobasystems / alpine-mariadb

MariaDB running on Alpine Linux [Docker]
https://hub.docker.com/r/yobasystems/alpine-mariadb/
237 stars 71 forks source link

prepend `use $MYSQL_DATABASE;` to .sql files #58

Closed srtlg closed 1 year ago

srtlg commented 2 years ago

Hello, I am just wondering, how you use this feature. In my understanding those .sql files are scripts created by mysqldump for one database, that will become $MYSQL_DATABASE of the container. In my adaption, I found the following changes useful:


        for f in /docker-entrypoint-initdb.d/*; do
                case "$f" in
-                       *.sql)    echo "$0: running $f"; /usr/bin/mysqld --user=root --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
-                       *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mysqld --user=root --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
+                       *.sql)
+                               echo "$0: running $f"
+                               { echo "use \`$MYSQL_DATABASE\`;" ; cat "$f" ; } \
+                               | /usr/bin/mysqld --user=root --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0
+                               echo ;;
+                       *.sql.gz)
+                               echo "$0: running $f"
+                               { echo "use \`$MYSQL_DATABASE\`;" ; gunzip -c "$f" ; } \
+                               | /usr/bin/mysqld --user=root --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0
+                               echo ;;
                        *)        echo "$0: ignoring or entrypoint initdb empty $f" ;;
                esac
                echo
dominictayloruk commented 2 years ago

If you could tell us more about what this does then i will merge if it's useful.

srtlg commented 2 years ago

It lets you import the output of mysqldump Database directly into the container as it will not include the database name.

dominictayloruk commented 2 years ago

https://github.com/yobasystems/alpine-mariadb/commit/0f35a0e22b3e0002989bc09ae84e6b374473cb63

dominictayloruk commented 2 years ago

This has broken the image, i'm getting

/scripts/run.sh: line 76: syntax error: unexpected "}" (expecting ";;")