Technology Encyclopedia Home >How to initialize MariaDB database?

How to initialize MariaDB database?

To initialize a MariaDB database, follow these steps:

  1. Install MariaDB:
    First, ensure MariaDB is installed on your system. For example, on Ubuntu:

    sudo apt update
    sudo apt install mariadb-server
    
  2. Start and Enable MariaDB Service:
    Start the MariaDB service and enable it to run on boot:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    
  3. Secure the Installation:
    Run the security script to set a root password, remove anonymous users, and restrict root login:

    sudo mysql_secure_installation
    
  4. Log in to MariaDB:
    Access the MariaDB shell as the root user:

    sudo mysql -u root -p
    
  5. Create a Database:
    Inside the MariaDB shell, create a new database:

    CREATE DATABASE mydatabase;
    
  6. 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;
    
  7. 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.