To initialize a MariaDB database, follow these steps:
Install MariaDB:
First, ensure MariaDB is installed on your system. For example, on Ubuntu:
sudo apt update
sudo apt install mariadb-server
Start and Enable MariaDB Service:
Start the MariaDB service and enable it to run on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure the Installation:
Run the security script to set a root password, remove anonymous users, and restrict root login:
sudo mysql_secure_installation
Log in to MariaDB:
Access the MariaDB shell as the root user:
sudo mysql -u root -p
Create a Database:
Inside the MariaDB shell, create a new database:
CREATE DATABASE mydatabase;
Create a User and Grant Privileges:
Create a user and grant access to the database:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Exit the MariaDB Shell:
Exit the shell after setup:
EXIT;
For managed MariaDB services, Tencent Cloud Database for MariaDB provides automated provisioning, backups, and scaling. It simplifies deployment and management while ensuring high availability and security.