Run MariaDB on Linux.
Update repo and install MariaDB.
sudo dnf update -y && \
sudo dnf install mariadb-server -y
Create runtime file and set appropiate permissions.
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld # Assigns ownership of that directory to the mysql user and group.
-p - Ensures it doesn’t fail if it already exists.
Enable, start, and check status of MariaDB.
sudo systemctl enable mariadb && \
sudo systemctl start mariadb && \
sudo systemctl status mariadb
Restart:
sudo systemctl restart mariadb
Stop:
sudo systemctl stop mariadb
sudo mariadb-install-db --user=MySQL --basedir=/usr --datadir=/var/lib/mariadb
Enhance the security of your MariaDB installation and establish the root password.
sudo mariadb-secure-installation
What it does:
Main config file /etc/my.cnf.
Key configs:
[mysqld]
bind-address=127.0.0.1
port=3306
max_connections=200
Apply.
sudo systemctl restart mariadb
CREATE DATABASE kodekloud_db2;
GRANT ALL PRIVILEGES ON kodekloud_db2.* TO 'kodekloud_roy'@'%' IDENTIFIED BY 'dCV3szSGNA';
FLUSH PRIVILEGES;
sudo mariadb -u root -p
Show databases.
SHOW DATABASES;
Verify by connecting to MariaDB using the new user.
mariadb -u kodekloud_roy -p
Stop the database.
sudo systemctl stop mariadb
Start MariaDB in safe mode.
sudo mysqld_safe --skip-grant-tables --skip-networking &
Login without password
mariadb -u root
Reset the password
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost'
IDENTIFIED BY 'NewStrongPassword';
Stop the safe server.
sudo pkill mysqld
Start MariaDB normally.
sudo systemctl start mariadb
Test login.
mysql -u root -p
Log in as the root(or any user with CREATE USER / ALTER USER privileges).
While inside MariaDB, execute:
ALTER USER 'super_user'@'localhost' IDENTIFIED BY 'new_strong_password';
FLUSH PRIVILEGES;
EXIT;
Test.
mariadb -u super_user -p
Edit config /etc/my.cnf.
bind-address=127.0.0.1 ## Localhost access
bind-address=0.0.0.0 # Public access
For public access, open the firewall.
sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reload