CLI-based database provisioning is faster and more reliable for repetitive DirectAdmin operations, but small shell details can break automation.
Typical scenario
You are inside a customer path:
/home/user_name/public_html
And you want DB/user names based on the account prefix.
1) Common limitation of da utility
Some da versions do not support direct database creation and return:
Unknown command 'database'. Please specify one command of: admin, build, config...
In that case, use direct SQL execution via MySQL/MariaDB with DirectAdmin credential file.
2) Bash ! pitfall
Passwords containing ! may trigger history expansion:
-bash: !kL4kie: event not found
Escape it (\!) or use safe quoting strategy.
3) Inline provisioning command
One-liner example:
USER_NAME=$(pwd | cut -d'/' -f3) && mysql --defaults-extra-file=/usr/local/directadmin/conf/my.cnf -e "CREATE DATABASE IF NOT EXISTS ${USER_NAME}_db; CREATE USER IF NOT EXISTS '${USER_NAME}_user'@'localhost' IDENTIFIED BY 'MinhaSenhaComplexa\!2026'; GRANT ALL PRIVILEGES ON ${USER_NAME}_db.* TO '${USER_NAME}_user'@'localhost'; FLUSH PRIVILEGES;"
What it does
- Extracts account name from current path.
- Creates
${USER_NAME}_db. - Creates
${USER_NAME}_user. - Grants DB privileges.
- Flushes privilege cache.
4) Sync with DirectAdmin panel
When DB objects are created directly in MySQL, GUI may lag behind. Trigger task queue update:
/usr/local/directadmin/dataskq
Production best practices
- Verify extracted username before running batch automation.
- Avoid exposing root credentials in shell history.
- Enforce naming conventions per environment.
- Validate scripts in staging first.
Well-designed CLI automation reduces manual errors and deployment time. Mastering Bash escaping and DirectAdmin integration gives you safe and scalable provisioning workflows.
This post is licensed under CC BY-NC.
Comments
Join the discussion below.
Comments are not configured yet. Add Cusdis settings in /assets/json/config/blog-comments-config.json.