This post documents how to import
.sqlor.sql.gzbackup files into MariaDB (version 12.1.1) running inside a Docker container, including common mistakes and their fixes.
1. Background
When managing databases in containerized environments, it’s common to deploy MariaDB inside Docker and occasionally import database backups for restoration or migration.
Example environment:
| Item | Value |
|---|---|
| Container name | blognufacedb |
| MariaDB version | 12.1.1-MariaDB |
| Username | nuface |
| Password | abcd123 |
| Database name | nuface |
| SQL file | nuface_2025-09-16.sql |
2. The Original Command
docker exec -i blognufacedb mariadb -u nuface -p 'abcd123' --default-character-set=utf8mb4 nuface < nuface_2025-09-16.sql
After execution, the terminal displayed a long list of help text:
mariadb from 12.1.1-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper
Usage: mariadb [OPTIONS] [database]
...
MariaDB did not actually import anything—it simply printed the help message.
3. Root Cause
The issue was:
There is an extra space after
-p.
MariaDB interprets 'abcd123' as a database name, not a password.
This causes the command arguments to shift and results in the help screen being displayed.
4. Correct Import Commands
✅ Method 1: Use -p'password' (No space!)
docker exec -i blognufacedb \
mariadb -u nuface -p'abcd123' --default-character-set=utf8mb4 nuface \
< nuface_2025-09-16.sql
✅ Method 2: Use --password=
docker exec -i blognufacedb \
mariadb -u nuface --password='abcd123' --default-character-set=utf8mb4 nuface \
< nuface_2025-09-16.sql
✅ Method 3: Use Environment Variable (Recommended)
This avoids exposing your password in the command line or shell history.
docker exec -i -e MYSQL_PWD='abcd123' \
blognufacedb mariadb -u nuface --default-character-set=utf8mb4 nuface \
< nuface_2025-09-16.sql
5. Importing a Compressed File (.sql.gz)
gunzip -c nuface_2025-09-16.sql.gz | \
docker exec -i -e MYSQL_PWD='abcd123' \
blognufacedb mariadb -u nuface --default-character-set=utf8mb4 nuface
6. Advanced Options (for Large Databases)
To handle large imports more efficiently, add:
--max-allowed-packet=512M \
--init-command="SET time_zone='+08:00'; SET FOREIGN_KEY_CHECKS=0;"
Example:
docker exec -i -e MYSQL_PWD='abcd123' \
blognufacedb mariadb -u nuface --default-character-set=utf8mb4 nuface \
--max-allowed-packet=512M \
--init-command="SET time_zone='+08:00'; SET FOREIGN_KEY_CHECKS=0;" \
< nuface_2025-09-16.sql
7. Tips and Troubleshooting
- If your dump file already includes
CREATE DATABASEorUSE nuface;, you can omit the database name in the command. - If you encounter:
ERROR 1227 (42000): Access deniedIt’s usually due to insufficient privileges (e.g.,DEFINERstatements in views or routines). Use a user withCREATE ROUTINEorSUPERprivileges. - To verify connectivity before import:
docker exec -it blognufacedb mariadb -u nuface -p'abcd123' -e "SELECT VERSION();"
8. Summary
When importing SQL files into MariaDB running inside Docker, most issues stem from incorrect parameter syntax.
Keep these points in mind:
| Key Point | Explanation |
|---|---|
No space after -p | Otherwise, MariaDB misinterprets the argument |
Use MYSQL_PWD for security | Keeps passwords out of command history |
You can import .gz files directly with `gunzip -c | docker exec -i` |
Add --max-allowed-packet and --init-command for large files | Improves reliability |
📌 Related Articles
- mysqldump Export Syntax Notes (MySQL / MariaDB 5.5)
- Best Practices for MariaDB Backup and Restore in Docker