===== Quick Reference: Creating a New MariaDB Database and User =====
==== 1. Log into MariaDB ====
First, log into the MariaDB server using the root user:
mariadb -u root -p
==== 2. Create a New Database ====
Create a new database named `exampleDatabase`:
CREATE DATABASE exampleDatabase;
==== 3. Create a New User and Grant Permissions ====
Create a new user `exampleUser` with the password `examplePass` and grant them access to the new database. This user should be able to connect both from localhost and from other network devices.
CREATE USER 'exampleUser'@'localhost' IDENTIFIED BY 'examplePass';
CREATE USER 'exampleUser'@'%' IDENTIFIED BY 'examplePass';
GRANT ALL PRIVILEGES ON exampleDatabase.* TO 'exampleUser'@'localhost';
GRANT ALL PRIVILEGES ON exampleDatabase.* TO 'exampleUser'@'%';
==== 4. Apply Changes ====
Flush the privileges to ensure that the changes take effect:
FLUSH PRIVILEGES;
==== 5. Exit MariaDB ====
Exit the MariaDB shell:
EXIT;
===== Additional Notes =====
- Ensure that MariaDB is configured to accept remote connections. This typically involves editing the /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf file and commenting out the line bind-address = 127.0.0.1.
- Restart the MariaDB service after making configuration changes:
sudo systemctl restart mariadb
===== Summary =====
This guide walks you through the steps to create a new database and user in MariaDB, allowing access both locally and from remote network devices.