Technology Encyclopedia Home >How to create a MariaDB account?

How to create a MariaDB account?

To create a MariaDB account, you need to log in to the MariaDB server as a user with sufficient privileges (e.g., the root user) and use the CREATE USER statement. Here’s a step-by-step guide with an example:

  1. Log in to MariaDB:
    Use the MariaDB command-line client or a tool like phpMyAdmin to connect to the server. For example:

    mysql -u root -p
    

    Enter the root password when prompted.

  2. Create a new user:
    Use the CREATE USER statement to define the username and host. For example, to create a user named newuser who can connect from localhost:

    CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'strong_password';
    

    Replace strong_password with a secure password.

  3. Grant privileges (optional):
    If the new user needs access to specific databases or tables, grant permissions using the GRANT statement. For example:

    GRANT ALL PRIVILEGES ON mydatabase.* TO 'newuser'@'localhost';
    

    This grants full access to mydatabase for newuser.

  4. Flush privileges (if needed):
    If you modify privileges directly in the mysql database, run:

    FLUSH PRIVILEGES;
    

    (This is usually not required after GRANT or CREATE USER.)

  5. Verify the account:
    Check if the user exists:

    SELECT User, Host FROM mysql.user;
    

Example:

CREATE USER 'appuser'@'%' IDENTIFIED BY 'secure123';
GRANT SELECT, INSERT ON appdb.* TO 'appuser'@'%';
FLUSH PRIVILEGES;

For managed MariaDB services, Tencent Cloud Database for MariaDB simplifies user management. You can create accounts via the Tencent Cloud Console or API, with built-in security features like password policies and access control.