Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo apt update
- Install MariaDB
Install MariaDB using theapt
package manager:
sudo apt install mariadb-server
- Secure MariaDB Installation
Run the security script that comes pre-installed with MariaDB to improve the security of your installation:
sudo mysql_secure_installation
This script will prompt you to set a root password, remove anonymous users, disallow root login remotely, remove test databases, and reload the privilege tables. Follow the prompts and answer accordingly.
- Verify MariaDB Installation
Check the MariaDB service status to ensure it is running:
sudo systemctl status mariadb
If MariaDB is running, you should see an active (running) status.
- Log In to MariaDB
Log in to the MariaDB root administrative account:
sudo mysql -u root -p
You will be prompted to enter the root password you set during the secure installation process.
- Create a New Database (Optional)
To create a new database, use the following SQL command within the MariaDB prompt:
CREATE DATABASE your_database_name;
- Create a New MariaDB User (Optional)
To create a new MariaDB user and grant it permissions, use the following SQL commands:
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;
This will create a new user and grant them all privileges on the specified database.
- Test MariaDB
To verify that MariaDB is functioning correctly, exit the MariaDB prompt and try logging in as the new user:
mysql -u your_username -p
You will be prompted to enter the password for the new user. Once logged in, you can list the available databases to ensure your new database is present:
SHOW DATABASES;
- Backup and Restore Databases (Optional)
To back up a database, use themysqldump
command:
mysqldump -u your_username -p your_database_name > your_database_name.sql
To restore a database from a backup file, use the mysql
command:
mysql -u your_username -p your_database_name < your_database_name.sql