Import, export and make backups of MySQL/MariaDB databases.
Easy with Basher
basher install nelson6e65/bash-mysql-helper
Done!
mysql-helper
uses a .env
file to read database credentials.
Example of a .env
file content:
# Optional
DB_HOST='localhost'
DB_PORT=3306
# Mandatory
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
# Other stuffs not used by `mysql-helper`...
It creates a backup file: {database}_{date}.sql.gz
file.
mysql-helper b
mysql-helper backup
You can ignore backup creation by using --no-backup
Exports DB to {database}.sql
file.
mysql-helper e
mysql-helper export
# mysql-helper -e # DEPRECATED
# mysql-helper --export # DEPRECATED
Import a database content from {database}.sql
file.
mysql-helper i
mysql-helper import
# mysql-helper -i # DEPRECATED
# mysql-helper --import # DEPRECATED
Note: By default it will run
backup
automatically. To avoid this, pass--no-auto-backup
.
By default, it will use the working directory to search files. In order to use a different target-dir:
mysql-helper (i|e|b) <target-dir>
mysql-helper (i|e|b) --target <target-dir> # DEPRECATED
Use --help to see more options.
mysql-helper --help
Some tools used: