First, log into the MariaDB server using the root user:
mariadb -u root -p
Create a new database named `exampleDatabase`:
CREATE DATABASE exampleDatabase;
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'@'%';
Flush the privileges to ensure that the changes take effect:
FLUSH PRIVILEGES;
Exit the MariaDB shell:
EXIT;
- 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
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.