Setting Up a MySQL Database and User

Last update: 06-05-2024

If you're working on a project that requires a MySQL or MariaDB database, here’s a quick guide to help you set up a database and create a user with the necessary privileges.

mysql -u root -p
CREATE DATABASE dbname;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
exit

Steps:

  1. Log in to MySQL or MariaDB as the root user. There are a few options for that:
  2. Create a new database (replace dbname with the actual name you want to use):
  3. CREATE DATABASE dbname;
  4. Create a new user and assign a password (replace username and password with the actual username and password you want to use):
  5. CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
  6. Grant all privileges on the new database to the new user (replace dbname and username with the actual database name and username):
  7. GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
  8. Exit MySQL/MariaDB:
  9. exit

And that's it! You now have a new database and a user with full privileges on it. This setup is ideal for development environments or when setting up a new project.

0 Comments

Add a new comment: