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.
-
Login to MySQL as Root
mysql -u root -pEnter your MySQL root password when prompted.
-
Create a New Database
CREATE DATABASE my_database; -
Create a New MySQL User
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password'; -
Grant Access to the Database
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost'; -
Apply the Changes
FLUSH PRIVILEGES; -
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