New MariaDB Script

New MariaDB Script

New MariaDB is a bash script that automates the creation of a new database and user in MariaDB. It simplifies the process by prompting for necessary credentials and applying appropriate privileges.

Features

  • Creates a new MariaDB database.
  • Creates a new user and assigns privileges.
  • Ensures database and user creation only if they do not already exist.
  • Supports using credentials from ~/.my.cnf if available.
  • Secure password handling during input.

Requirements

Before running the script, ensure that:

  • You have MariaDB installed and running.
  • You have SUPER or GRANT OPTION privileges to MariaDB.

Usage

Running without arguments 

If you run the script without any arguments:

./new-mariadb.sh

It will:

  • Check if ~/.my.cnf exists.
  • Attempt to authenticate using credentials stored in ~/.my.cnf.
  • Validate that the credentials have SUPER or GRANT OPTION privileges.

If valid, the script will proceed.

Running with admin user argument

If ~/.my.cnf is not present or invalid, you can manually provide the admin username with:

./new-mariadb.sh -u <admin_user>

You will then be prompted securely during execution for:

  • Admin password (for authentication)
  • New Database Name
  • New Username
  • New Password (entered securely)

Important Notes

  • The script ensures that the database and user are created only if they do not already exist.
  • User credentials are entered securely and not exposed in the command line.
  • The script validates that the admin user has sufficient privileges before proceeding.

Get the Script

new-mariadb

https://github.com/PaulSorensen/new-mariadb

Creates a new database and user on MariaDB.

Last Updated: April 27, 2025

Categories: Scripts