Creating a database in MySQL and MariaDB is a common task for developers and administrators. These two database management systems are widely used, open-source, and offer powerful tools for creating, managing, and querying data. Assigning permissions to a database is essential for controlling user access and ensuring data security. In this guide, we will walk through the process of creating a database, adding a user, and assigning permissions on MySQL and MariaDB in a few simple steps.

To follow this guide, you'll need to have MySQL or MariaDB installed on your system. MySQL and MariaDB share similar syntax and functionality, so the steps outlined in this guide will work for both systems. You'll also need to have access to the command-line interface or a graphical user interface (GUI) tool for managing databases.

By the end of this guide, you'll have a new database, a user with the necessary permissions, and a better understanding of how to manage databases in MySQL and MariaDB. Here's a step-by-step guide to help you accomplish this:

Steps to create a new database on MySQL and MariaDB:

  1. Open your terminal or command prompt.
  2. Connect to your MySQL or MariaDB server using the following command.
    mysql -u root -p
  3. Enter your MySQL or MariaDB root password when prompted.
  4. Create a new database with the following command, replacing “your_database” with the desired database name.
    CREATE DATABASE your_database;
  5. Create a new user with the following command, replacing “your_username” and “your_password” with your desired values.
    CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
  6. Grant the necessary permissions to the new user on the database with the following command, replacing “your_username” and “your_database” with the appropriate values.
    GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost';
  7. Flush the privileges to apply the changes using the following command.
    FLUSH PRIVILEGES;
  8. Exit the MySQL or MariaDB command-line interface with the following command.
    EXIT;

Now you have successfully created a database, added a user, and assigned permissions in MySQL or MariaDB. You can now use this new database and user to manage and query data securely.

Discuss the article:

Comment anonymously. Login not required.