Skip to content

Import, export and make backups of MySQL/MariaDB databases using .env file

License

Notifications You must be signed in to change notification settings

nelson6e65/bash-mysql-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql-helper

Import, export and make backups of MySQL/MariaDB databases.

Installing

Easy with Basher

basher install nelson6e65/bash-mysql-helper

Done!

Configuring

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`...

Usage

Backup Database

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

Exporting Database to SQL

Exports DB to {database}.sql file.

mysql-helper e
mysql-helper export
# mysql-helper -e # DEPRECATED
# mysql-helper --export # DEPRECATED

Importing SQL to Database

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.

Customize target dir

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

More options

Use --help to see more options.

mysql-helper --help

Credits

Some tools used: