alpine-mariadb icon indicating copy to clipboard operation
alpine-mariadb copied to clipboard

prepend `use $MYSQL_DATABASE;` to .sql files

Open srtlg opened this issue 3 years ago • 4 comments

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

srtlg avatar Jan 29 '22 17:01 srtlg

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

dominictayloruk avatar Mar 01 '22 11:03 dominictayloruk

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

srtlg avatar Mar 02 '22 08:03 srtlg

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

dominictayloruk avatar Mar 02 '22 11:03 dominictayloruk

This has broken the image, i'm getting

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

dominictayloruk avatar Mar 02 '22 15:03 dominictayloruk