← Back to Blog
Utility

Create a new Mysql User , Database , Assign access to DB user and import .sql file from Command line ?

Learn how to create a MySQL database and user, grant database permissions, and import a .sql backup file using simple command-line commands. This step-by-step guide includes practical examples for beginners and system administrators managing MySQL databases on Linux or Windows.

  1. Login to MySQL as Root

    mysql -u root -p

    Enter your MySQL root password when prompted.

  2. Create a New Database

    CREATE DATABASE my_database;
  3. Create a New MySQL User

    CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';
  4. Grant Access to the Database

    GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
  5. Apply the Changes

    
    FLUSH PRIVILEGES;
  6. Import .sql File into the Database

Use this command from the terminal, not inside MySQL:

mysql -u my_user -p my_database < your/path/file.sql