Two Women Looking at the Code at Laptop

How to Import MySQL Database or SQL File

This guide equips you with the essential commands to manage your MySQL databases. Learn how to import an existing SQL file or create a backup by exporting your database as an SQL file.

  • Access MySQL with Root User
mysql -u root -p
  • Create New Database
Syntax:- CREATE DATABASE Database_name;
Example:- CREATE DATABASE osmsdb;
  • Access Newly Created Database
Syntax:- USE Database_name;
Example:- USE osmsdb;
  • Import Database or SQL File
Syntax:- source sql_file_path
Example:- source /var/myimporteddb/osmsdb.sql

How to Export MySQL Database as SQL File

  • Export MySQL Database as SQL File
Syntax:- mysqldump -u db_user_name -p Database_Name > File_Path/File_Name.sql
Example:- mysqldump -u root -p dps > /var/myexporteddb/dps.sql